Merge CLR states that share the same LR(0) core. Same state count as SLR, nearly the power of CLR. The algorithm behind yacc, bison, and most real-world parser generators.
CLR produces many states that have the same LR(0) core but different lookaheads. These states do the same parsing work — they only differ in when to reduce.
Consider the LR0 grammar S→CC, C→cC|d. CLR produces separate states for each unique (core, lookahead) combination. Below is a concrete example of two states that CLR distinguishes but LALR merges:
States are mergeable when they have the same LR(0) core: the set of (production, dot) pairs, ignoring lookaheads.
Watch how CLR states are grouped by core and their lookaheads are unioned to form LALR states.
Built from the merged LALR states. Compare with the CLR table — for this grammar they are identical, confirming LALR introduces no extra conflicts here.
Each LALR state shows which CLR states were merged into it and the combined lookaheads. Fewer states than CLR, same structure as SLR's LR(0) collection.
Simulating input id = id $ with the LALR table.
Demonstrates that LALR accepts the same language as CLR for this grammar.
| Stack (state) | Remaining Input | Action | Note |
|---|
Understanding the trade-offs between the two approaches.
| Property | CLR (Canonical LR(1)) | LALR |
|---|---|---|
| Lookahead source | Exact per-item lookahead (computed during closure) | Union of merged states' lookaheads |
| State count | Larger — one state per unique (core, lookahead) combination | Fewer — same as LR(0)/SLR (one state per core) |
| Memory usage | Higher (more states → larger tables) | Lower (fewer states → compact tables) |
| Expressive power | Slightly more — can parse all LALR(1) grammars + a few more | Slightly less — may fail on some LR(1) grammars |
| Shift/reduce conflicts | Almost none (exact lookaheads prevent false conflicts) | Almost none (union lookaheads still precise enough usually) |
| Reduce/reduce conflicts | Almost none for unambiguous grammars | Rare but possible (introduced by merging incompatible lookaheads) |
| Build time | Longer (more states to compute) | Shorter (or equivalent via merging CLR states) |
| Used in practice | Rarely alone (too expensive for large grammars) | ✓ yacc, bison, CUP, ANTLR, most production tools |
From the simple but conflict-prone LR(0) to the practical powerhouse LALR — each step solves the previous approach's key weakness.