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:
- Stop the conversion right now and say the grammar, that constructed this state machine, is not a LALR(1) grammar,
- or should I continue merge other possible states and stop only if none of such candidates can be merged?
CodePudding user response:
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.)