Relationship Between SLR and LALR Parser State Counts (n1n_1 vs n2n_2)

Relationship Between SLR and LALR Parser State Counts (n1n_1 vs n2n_2)

Verified Sources
Sep 12, 2026

In LR-family parsing, SLR(1) and LALR(1) both use the same underlying LR(0) state automaton (same viable-prefix sets / kernels), and differ only in how lookahead symbols are used to place reduce actions in the parse table. In particular, the LALR(1) simplification merges/represents LR(1) states with identical LR(0) cores, and this process yields an automaton whose number of states equals the LR(0) (hence equals the SLR(1)) state count. Therefore, for a grammar GG, if the SLR parser has n1n_1 states and the LALR parser has n2n_2 states, we have: n1=n2n_1 = n_2.3

A useful mental model is summarized by the hierarchy:

Here, LALR(1) is “more precise than SLR(1)” in its lookaheads, but it does not introduce additional LR(0) states—so the state count stays the same.2

Correct option: (i) n1=n2n_1 = n_2.

Footnotes

  1. LALR parser - Wikipedia - States are merged by identical kernel item sets; describes power vs SLR and how merging works. 2

  2. LR parser - Wikipedia - States: LALR has the same states as SLR but uses more precise lookahead; also contrasts with canonical LR/CLR behavior. 2

  3. SLR(1) vs LALR lookahead sets (University of Pennsylvania CIS 5110 notes) - SLR uses FOLLOW-based lookaheads; LALR uses sharper lookahead sets while relying on the LR(0) characteristic automaton structure.

How LR lookahead methods affect states

No lookahead

LR(0)

States are built from LR(0) items (viable prefixes / cores)."

Follow-based reduce placement

SLR(1)

Use FOLLOW sets to decide where reductions go, but keep the same LR(0) states."

Merged lookaheads per LR(0) core

LALR(1)

Merge LR(1) states with identical LR(0) cores; state count matches LR(0)/SLR."

Canonical LR(1) (splits cores)

CLR(1)

May increase number of states because lookahead distinguishes otherwise identical cores."

Key concepts you need

  • LR(0) core: LALR merges states with the same LR(0) core.
  • Lookahead: affects reduce placement, not LR(0) state construction.
  • FOLLOW set: used by SLR to place reductions.
  • Merge by kernel: characteristic of LALR.

Why the state counts match (n1=n2n_1=n_2)

  • LALR(1) “merges rules that have identical kernel item sets” (LR(0) cores), because LR(0) state construction does not yet know lookaheads.
  • LALR and SLR both correspond to using the same LR(0) viable-prefix state automaton; they differ only in lookahead computations for reductions.2
  • Multiple sources explicitly state that LALR has the same number of states as SLR (and LR(0)), with LALR being more powerful than SLR but not increasing state count.3

Footnotes

  1. LR parser - Wikipedia - States: LALR has the same states as SLR but uses more precise lookahead; also contrasts with canonical LR/CLR behavior. 2

  2. SLR(1) vs LALR lookahead sets (University of Pennsylvania CIS 5110 notes) - SLR uses FOLLOW-based lookaheads; LALR uses sharper lookahead sets while relying on the LR(0) characteristic automaton structure. 2

  3. LALR parser - Wikipedia - States are merged by identical kernel item sets; describes power vs SLR and how merging works. 2

Exam-style reasoning for the relation between $n_1$ and $n_2$

  1. 1
    Step 1

    SLR uses FOLLOW sets; LALR uses lookahead computed via merging LR(1) states but based on identical LR(0) cores.

  2. 2
    Step 2

    LALR merges states with identical LR(0) kernels, so it does not create extra LR(0)-level states.

  3. 3
    Step 3

    Therefore the number of parser states remains the same: n1=n2n_1=n_2.

Pro Tip

When a question asks only for the number of states, check whether the method changes the LR(0) state automaton. If it only refines lookahead placement, the state count often remains equal (as with SLR vs LALR).

Common confusion to avoid

LALR(1) is more powerful than SLR(1), but “more powerful” here comes from more precise lookaheads, not from introducing more LR(0) states. So you should not assume LALR has more states than SLR.

Relative state-count behavior across LR variants

State counts depend on how lookahead distinguishes (or merges) LR(0) cores.

Quick FAQ

Knowledge Check

Question 1 of 3
Q1Single choice

Consider a grammar GG whose SLR parser has n1n_1 states and LALR parser has n2n_2 states. The relation between n1n_1 and n2n_2 is: