in Compiler Design edited by
1,000 views
0 votes
0 votes

E--> E+E

E--> E*E

E--> id

Input string: id + id + id

in Compiler Design edited by
1.0k views

3 Answers

0 votes
0 votes

For the string “ id + id + id” is generated by this grammar then there will be 2 parse tree

e.g. 1: 

For the string "3 * 2 + 5",

For the string "3 * 2 + 5", the above grammar can generate two parse trees

Ambiguity in Grammar

Since there are two parse trees for a single string "3 * 2 + 5", the grammar G is ambiguous.

Total 2  parse trees for a single string "3 * 2 + 5”

 

e.g. 2: For the string " id * id + id * id", there will be more than two parse tree

So, by grammar, we can only conclude whether it is ambiguous.

and there should be a string given for the number of parse trees generated.

edited by
0 votes
0 votes
There will be 2 parser tree one by replacing left most variable with I'd and another by replacing rightmost variable by id
0 votes
0 votes

For the given input string id+id+id

There is only two possible parse tree

And for the string id*id+id 

​​​​​​There will be more than one

​​​

edited by