Solution for the Spring 04 midterm. by Sean Cahill

1 a. Thompson's construction is a method for automatically building a NFA from a regular expression.

1 b. Bison creates a bottom-up parser.

1 c. The resulting SLR table would have a shift-reduce conflict if y (a symbol from the grammar)
is an element of follow (B).

2.
AB
*[135][2][5]
[2][-][135]
*[5][-][5]

3. a.

3. b. action table
AB
statead$
0---
1--acc
2---
3r3r3r3
4--r1
5r2r2r2

Note: <eps> denotes the epsilon symbol in the rules below.

4. a. It accepts strings w/ a leading ','. For example, the string: , expr, expr would be accepted.

4. b.
list -> <eps> | list1
list1 -> expr | list1 , expr

4. c.
<eps> | expr (, expr)*

5.
E--> E1 + T { $$ = "(+" + $1 + " " + $3 + ")"; }
| T { $$=$1; }

T--> T1 * F { $$ = "(*" + $1 + " " + $3 + ")"; }
| F { $$ = $1; }

F --> id { $$ = $1; }
| (E) { $$ = $2; }

6 (extra credit).
plusExpr --> id + pERest
{$$= "(" + $1 + " " + $3 + ")" ;}
pERest --> id {$$ = $1 ; }
| id + pERest
{$$ = $1 + " " + $3; }





The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees