Notes on LALR parse table.
. Merging items may result into conflicts in LALR parsers which did not exist in LR parsers
. New conflicts can not be of shift reduce kind:
- Assume there is a shift reduce conflict in some state of LALR parser with items
{[X
α .,a],[Y
γ .a ß ,b]}
- Then there must have been a state in the LR parser with the same core
- Contradiction; because LR parser did not have conflicts
. LALR parser can have new reduce-reduce conflicts
- Assume states
{[X
α ., a], [Y
ß ., b]} and {[X
α ., b], [Y
ß ., a]}
- Merging the two states produces
{[X
α ., a/b], [Y
ß ., a/b]}
Merging states will never give rise to shift-reduce conflicts but may give reduce-reduce conflicts and have some grammars which were in canonical LR parser may become ambiguous in LALR parser.
To realize this, suppose in the union there is a conflict on lookahead a because there is an item [A
α . ,a] calling for a reduction by A
α , and there is another item [B
ß .a γ ,b] calling for a shift. Then some set of items from which the union was formed has item [A
α . ,a], and since the cores of all these states are the same, it must have an item [B
ß .a γ ,c] for some c. But then this state has the same shift/reduce conflict on a, and the grammar was not LR(1) as we assumed. Thus the merging of states with common core can never produce a shift/reduce conflict that was not present in one of the original states, because shift actions depend only on the core, not the lookahead.
But LALR parser can have reduce-reduce conflicts. Assume states {[X
α ., a], [Y
ß ., b]} and {[X
α ., b], [Y
ß ., a]}. Now, merging the two states produces {[X
α ., a/b], [Y
ß ., a/b]} which generates a reduce-reduce conflict, since reductions by both X
α and Y
ß are called for on inputs a and b.