
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!

Consider the following grammar G:
S! A S j A! a A j b
1 [40]. If G is a grammar of the following typ e, give the appropriate parsing tables; if not, explain why not. (Note: Rememb er to give parsing tables if the grammar is of the indicated typ e. A yes/no answer is not sucient.) (a) LL(1) (b) LR(0) (c) SLR(1) (d) LR(1) (e) LALR(1)
2 [10]. Show that the language generated by G is a regular language.
3 [10]. What are the characteristics of an SLR(0) grammar? In particular, compare SLR(0) grammars to one or more of the classes of grammars that we have already studied (e.g., the 5 classes asked for in question 1 ab ove). Explain your answer.
4 [8]. Give the pre x and p ost x for each of the following: (a) (a+b)/(c+d)+(e+f ) (b) a/b/c+d+e
5 [10]. Consider the regular expression: (0?^ 1)?^ (0?^ 1)
Give the minimal state DFA that accepts this set.
6 [12]. Attribute grammars: (a) In YACC, rules like: Expr : Expr '+' Term f$$ = $1 + $3g represent (inherited, synthesized) [pick one] attributes.
(b) Why do es YACC use an LR or LALR parsing algorithm rather than an LL parsing algorithm? Explain this relative to the question of using attribute grammars.
(c) Could a to ol somewhat like YACC b e develop ed that used a precedence parsing algorithm? Explain.
(d) Assume you have an attribute code that output the p ost x for a nonterminal, and an attribute ty pe that gave the typ e of data represented by a nonterminal (either integ er or r eal ). Give a p ossible de nition for E :code in the pro duction of part (a) that allows for co ersion of integer to real data.
7 [10]. Answer or explain each of the following statements with a short explanation (2-3 sentences each).
(a) The pumping lemma can b e used to show that a given language can b e generated by a context free grammar.
(b) If a grammar is ambiguous, the language it generates cannot b e LR(1).
(c) Since the regular expression a?^ b?^ can b e used to generate an^ bn^ , that means the language an^ bn^ is a regular language since it is generated by a regular expression.