# Removing conflicts of LR(1) parsing tables

S' -> S \$

S -> I ; S
S -> return E ; S
S -> return I ; S
S -> ''

I -> id
I -> id = E
I -> id = I

E -> C && C
E -> C || C
E -> ! C
E -> C

C -> A > A
C -> A < A
C -> A >= A
C -> A <= A
C -> A == A
C -> A

A -> T A'
A'-> + T A'
A'-> - T A'
A'->''

T -> F T'
T'-> * F T'
T'-> / F T'
T'->''

F -> id
F -> const
F -> ( A )


This is supposed to be a LR(1) grammar, but its LR(1) parsing table have a conflict on the ; symbol column: it has both a shift and a reduction transition. How this conflict can be removed?

• If it is supposed to be an LR grammar, why have you chosen to deform it to remove left-recursion? – rici Jun 22 '18 at 20:42

The ambiguity comes from

I -> id


because that rule means that both I ans E derive id, which in turn means that return id could be a derivation of either:

S -> return E ; S


or

S -> return I ; S


Also, id1 = id2 could be derived from:

I -> id = E


or

I -> id = I


It doesn't make sense for id to be a statement if id + 3 is not; I'd just drop the I -> id production.