The Gateway to Computer Science Excellence
0 votes
1k views
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.
in Compiler Design by | 1k views

2 Answers

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.
by
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.
by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,485 answers
201,816 comments
95,291 users