Consider the following grammar:
E ! E op E | (E) | num
op ! + | * | ^
This grammar is ambiguous; we would like the grammar to have parse trees in
which exponentiation (^) has higher precedence than multiplication (*), and
both have higher precedence than addition (+).
- Write an LL(1) grammar that accepts the same language as this grammar
and respects the desired operator precedence. (You need not ensure that the
operators are left-associative, however.)
- Show the derivation of the expression 2^3 + 4*5 using the grammar of
part (a).
- Write an LR(1) grammar that accepts the same language, but enforces both
the correct precedence and left-associativity of the operators.