CS321 Prog Lang & Compilers Assignment # 8
Assigned: Feb. 14, 2007 Due: Monday. Feb 19, 2007
In the grammars below, all symbols that start with an
upper case letter are Non-terminals, and all other
symbols are terminals. The symbol [empty] represents
the empty string.
1) Remove the left recursion from the grammar below.
Subject ::= Article Nounphrase
Article ::= the | a
NounPhrase ::= Adjective Noun
Adjective ::= Adjective pretty
| Adjective red
| [empty]
Noun ::= ball | cat
2) The grammar below is both ambiguous and left recursive.
It is ambiguous because the string "x :: [y] ++ [z]" has at
least two parses. Refactor the grammar using levels, where
(x :: [y]) ++ [z] has precedence over x :: ([y] ++ [z]) and
also remove the left recursion.
List ::= [ Item Items ]
| [ ]
| Item :: List
| List ++ List
Items ::= Items , Item
| [empty]
Item ::= id
Back to CS 321, Languages and Compiler Design, Assignment Page