2,899 views
0 votes
0 votes
Given an Operator Grammar as,

E -> E*F / F+E / F

F -> F-F / id

How to determine associativity in this case? Since Operator grammar can be ambiguous also.

Is the above question solved using associativity and precedence of operators we consider in C programming? or it is Different.

2 Answers

0 votes
0 votes
See recursive nature of the grammar.

If any production is left recursive then the associativity of operator will be left.

In case right recursive, the right associativity.

Also when parse tree is made, operator that comes at lower level has higher associativity like here - > * and  - > +.

If operands are same then generally +, *, - are left associative.
0 votes
0 votes
If the grammar isn't ambiguous we can directly get the the associativity and precedence from the grammar. But operator precedence grammar is ambiguous hence we mayn't always get these from it.

E -> E*F / F+E / F

* and + have equal precedence, + is right associative and * is left associative.

 F -> F-F / id

Here F can be both left and right associative.

So in case of ambiguous grammar we can sometimes get precedence and associativity.

Related questions

0 votes
0 votes
1 answer
1
Sanjay Sharma asked Oct 29, 2017
1,451 views
Given P,Q,R are non- terminals and r , s ,t are terminals ,which of the following grammar rule(s) violate the requirements of an operator grammarI P->QRII P->QsRIII P- ...
0 votes
0 votes
0 answers
3
Rahul Ranjan 1 asked May 29, 2018
526 views
Given an operator grammar :$E - E * F / F + E / F$$F - F - F / id$ Is this table correct for the above operator grammar ?