Niroj
Niroj

Reputation: 1114

Conflict in CLR parsing

This is the grammar:

S' -> S
S-> aBc|bCc|aCd|bBd
B ->e
C ->e

I parsed in CLR then reduce/reduce conflict arose. What to do next? I have attached my solved problem below.

Parse Table

This is process

Upvotes: 2

Views: 2022

Answers (1)

LeleDumbo
LeleDumbo

Reputation: 9340

Anybody please tell me what to do next

Err... fix the conflict?

It's very clear even just from the last two productions, when the parser meets either c or d after e:

B -> e . {c, d}
C -> e . {c, d}

single lookahead is not enough to determine whether above condition should reduce to B or C.

Parser generators usually have a solution by taking the one that appears first in the grammar, but this is not always a good case. In above grammar, if this solution is taken, the parser won't be able to parse bec and aed due to e always reduces to B.

I suggest changing the grammar such that no conflict occurs. You know the whole grammar can only produce aec, bec, aed and bed. See what's better in the sequences to be made separate production that will reduce uniquely.

Upvotes: 3

Related Questions