1.6k views

Consider the context-free grammar

$E \rightarrow E + E$
$E \rightarrow (E * E)$
$E \rightarrow id$

where $E$ is the starting symbol, the set of terminals is $\{id, (,+,),*\}$, and the set of nonterminals is $\{E\}$.

Which of the following terminal strings has more than one parse tree when parsed according to the above grammar?

1. $id + id + id + id$
2. $id + (id* (id * id))$
3. $(id* (id * id)) + id$
4. $((id * id + id) * id)$

edited | 1.6k views
0

by Boss (19.9k points)
edited by
+2
For option D to get nested brackets we will have yo use E→(E∗E) twice. We are left only one option to generate + id part. How are you getting 2?

Can you please show the derivation?
0

My Bad @tusharp. I got two trees coz I ignored the brackets. Option A is the only right choice. Thanks!

0
@digvi i m getting 2 parse tree in option D, while ignoring precdence. plz ckeck it.
5 parse trees
by Loyal (8.1k points)