retagged by
1,180 views
2 votes
2 votes
If I have the grammar :

E->E*F | F+E |F

F->id ,

Now here although + and * are defined at the same level , with different associativity but this grammar produces 2 different parse trees for the string id+id*id , so here we can't make any generalization regarding precedence of the operators although they are defined at the same level .

So what conclusion can be drawn from this ?
retagged by

3 Answers

1 votes
1 votes

The grammar is ambiguous since there are two leftmost derivations for the string id+id*id.

* and + have same precedence .as they are on same level.

* is left associativity and + is right associativity.

edited by
1 votes
1 votes
  • * and + have same precedence .
  • * is left associativity and + is right associativity.
  •  grammar is ambiguous
0 votes
0 votes
Yes as + and * are at same level so you can say they have the same precedence.In fact you need to have precedence of operators even for ambiguous grammar only then you can convert it to unambiguous. We use precedence and associativity for converting ambiguous to unambiguous.

Related questions

0 votes
0 votes
3 answers
1
0 votes
0 votes
1 answer
2
saumya mishra asked Jun 15, 2018
2,212 views
What is the difference between operator grammar and operator precedence grammar?
0 votes
0 votes
1 answer
3
jatin khachane 1 asked Jun 7, 2017
500 views
E → E + E | E * E | ( E ) | idWhat will be operator precedence for above grammar.Is precedence differs due to ambiguity