Professional Documents
Culture Documents
Resolving conflicts can be done by either one of the two following methods
E → E + E | E * E | ( E ) | id
We know that ‘+’ and ‘*’ are left associative and ‘*’ is having precedence over ‘+’
Method 1:
E’ → E E → E + E E → E * E E → ( E ) E → id
and the LR(0) items are:
I0:
E’→.E
E→.E+E I5:
E→.E*E E→E*.E
E→.id E→.E+E
I1: E→.E*E
E’→E. E→.(E)
E→E.+E E→.id
E→E.*E I6:
I2: E→(E.)
E’→.E E→E.+E
E→.E+E E→E.*E
E→.E*E I7:
E→.(E) E→E+E.
E→.id E→E.+E
I3: E→E.*E
E→.id I8:
I4: E→E*E.
E→E+.E E→E.+E
E→.E+E E→E.*E
E→.E*E I9:
E→.(E) E→(E).
E→id
Creating LR parser for Ambiguous Grammar:
Method 1:
While designing SLR parser table using it’s algorithm, conflicts arise as the
grammar is ambiguous
After resolving conflicts, the SLR parsing table is as shown in the table.