



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




(b) Give a parse tree for the string. (5 pts) Ans: S( S( S(a), S(a), + ), S(a), # ). Note: we use S(t1,t2,,,,tn) to represent a tree with root S and subtrees t1,t2,…,tn.
(c) Is the grammar ambiguous or unambiguous? why? (5pts)
Ans: No, since it can be shown that for every input, there is at most one parse tree for it.
(d) Describe the language generated by this grammar? ( 5 pts)
Ans: It is the set of the postfix forms of all expressions which are composable by two binary operators (+ and #) and one constant a.
Ans: ______________T',E'__________ (b) Fill in the following table with FIRST and FOLLOW sets for the grammar: (10 pts)
N FIRST(N) FOLLOW(N) S (,d {} E (,d ),$ E' + ),$ T (,d +,),$ T' * +,),$ F (, d *,+,),$
(c) Complete the following LL(1) table for the grammar: (10 pts)
N \ Σ d^ +^ *^ (^ )^ $ S E$ err err E$ err err E TE' err err TE' err err E' err +TE' err err ε ε T FT' err err FT' err err T' err ε *FT' err ε ε F FÆ d error error FÆ(E) error error
(d) Is this grammar LL(1)? why? (4 pts) Ans: __Yes, since there is at most one rule in every cell of the LL(1) table.
Now let Last = { (A, a) ∈ N X Σ | ∃β∈(N U Σ)* s.t. A Æ* β a }.
1 2 x 3 x0 x 4 x1 x1 x 5 - x1 x0 x 6 x1 x1 x0 - x 7 x2 x1 x0 x1 x2 x 8 x1 - x0 x1 x1 x1 x 1 2 3 4 5 6 7 8
(b) Draw the minimized finite automata according the result of (a).
(b) Convert the NFA you got at (a) to an equivalent DFA by using the subset construction. Note: you must identify each state of your DFA with the set of old NFA states it corresponds to and make sure all unused states are removed. [10pts]
(a) Build the LR(0) NFA for this grammar [5pts]
(d) Is this an SLR(1) grammar? Give evidence. [5pts] Yes, since it is already an LR(0) grammar and every LR(0) grammar is a SLR(1) grammar.