Felix.leg
Felix.leg

Reputation: 749

Should a merge failure stop the LR(1) to LALR(1) conversion

Let's say I have got a set of LR(1) states and I want to try to convert it to LALR(1). I did the first step of finding states that have got the same LR(0) core and now I'm doing the merge process. However one of such set of states can't be merged, because it would introduce RR conflict(s). Should I:

Upvotes: 1

Views: 125

Answers (1)

rici
rici

Reputation: 241671

The conflict is not going to go away with more merges, so you could stop immediately and report failure.

Most parser generators would continue to the end, though:

  • The user might appreciate knowing about all conflicts and not just the first one found, in order to debug their grammar;
  • Sometimes a simple heuristic to resolve conflicts succeeds in generating a usable parser. (Yacc, for example, first resolves using declared operator precedences, then by preferring shift to reduce, and finally by preferring the reduction which appears earlier in the grammar.)

Upvotes: 1

Related Questions