Assignment title: Information
Exercise 2.2.1
Consider the context-free grammar
S S S + | S S * | a
a. Show how the string aa + a* can be generated by this grammar.
b. Construct a parse tree for this string.
c. What language does this grammar generate? Justify your answer.
Exercise 2.2.2
What language is generated by the following grammars? In each case justify your
answer. Also describe each language informally using a sentence or two in English.
a. S 0 S 1 | 0 1
b. S + S S | - S S | a
c. S S ( S ) S | ε
d. S a S b S | b S a S | '
e. S a | S + S | S S | S * | ( S )
Exercise 2.2.3
Which of the grammars in Exercise 2.2.2 are ambiguous?
Exercise 2.3.1
Construct a syntax-directed translation scheme that translates arithmetic
expressions from infix notation into prefix notation in which an operator appears
before its operands; e.g., -xy is the prefix notation for x – y. Give annotated parse
trees for the inputs 9-5+2 and 9-5*2.