Choose the Correct Answer: Shift–Reduce Conflicts in LALR(1) Parsers

Choose the Correct Answer: Shift–Reduce Conflicts in LALR(1) Parsers

Verified Sources
Nov 4, 2026

A grammar GG has a shift–reduce conflict in a particular LR-style parser construction when, in some parsing state, the action table cell ACTION[i,a]ACTION[i, a] is forced to contain both a shift action and a reduce action for the same lookahead terminal aa.

In LR-family terms, we distinguish:

  • keyword: LR parser using only LR(0) items (no lookahead terminals).
  • keyword: Uses lookaheads from FOLLOW sets (coarse approximation).
  • keyword: Uses exact lookaheads computed per LR(1) items.
  • keyword: Approximates LR(1) by merging states with the same LR(0) core, unioning lookaheads.

The key fact behind the multiple-choice question is that LALR(1) is a “merged” version of LR(1): it can introduce conflicts that LR(1) might avoid, but it cannot “hide” conflicts that are already forced by the LR(0) core behavior.

A precise characterization (used in standard compiler-construction reasoning) is:

  • If LR(0) already forces a shift–reduce conflict in some state, then every LR variant that uses the same LR(0) core (including SLR(1), LALR(1), and LR(1)) will also have a shift–reduce conflict.
  • Conversely, if there is no shift–reduce conflict in the LR(0) automaton, then any shift/reduce ambiguity in LALR(1) must arise from lookahead behavior; that can occur only when lookaheads interact in LALR/SLR-style merging/approximation.

In the options given, the statement that matches this “iff” condition is that LALR(1) shift–reduce conflicts are present exactly when the LR(0) parser for GG has shift–reduce conflicts.

To visualize why, consider the LR(0) situation: a shift–reduce conflict at LR(0) level means there exists an LR(0) state containing an item of the form A→α∙aβA \to \alpha\bullet a\beta (shift possibility on terminal aa), and also an item of the form B→γ∙B \to \gamma\bullet (reduce possibility without any lookahead restriction at LR(0) level).

Since LALR(1) uses the same LR(0) cores for its merged states, that structural overlap cannot disappear by refining lookaheads; it persists and therefore yields a shift–reduce conflict.

Mermaid intuition (cores are what gets merged in LALR(1)):

Therefore, the correct choice is:

(iv) the SLR(0) parser for GG has S-R conflicts is not the intended option name (it’s a typo-like mismatch in the question). Interpreting the intended LR family consistently, the correct statement is option (ii).

Correct answer: (ii) the LR(0) parser for GG has S-R conflicts.

Note: Many textbooks phrase this using “LR(0) conflicts imply LR-family conflicts in that same merged core,” and the “iff” in this multiple-choice format aligns to LR(0) ⇔ LALR(1) for shift–reduce conflict presence (not necessarily the exact set of conflicts).

How lookaheads evolve across LR-family parsers

No lookahead

LR(0)

Actions determined purely by LR(0) item cores; conflicts can arise from core overlap."

FOLLOW-based lookahead

SLR(1)

Reductions apply on terminals in FOLLOW sets; fewer reductions get triggered than LR(0) but still approximate."

Merged LR(1) states

LALR(1)

Exact LR(1) lookaheads are approximated by merging same LR(0) cores; unions may reintroduce conflicts."

Exact lookahead

LR(1)

Most precise among the listed; can avoid conflicts introduced by approximation/merging."

Reasoning to select the correct option

  1. 1
    Step 1

    At the LR(0) level, a shift–reduce conflict occurs when a state contains both a completed item (dot at the end) and a non-completed item that enables shifting.

  2. 2
    Step 2

    LALR(1) states are built from LR(0) automaton states by merging LR(1) states that share identical LR(0) cores; thus the same shift+reduce core overlap—if it exists—cannot vanish.

  3. 3
    Step 3

    If LR(0) has an S–R conflict, LALR(1 must also). If LR(0) does not have such a conflict, then the core structural overlap is absent; any LALR(1 conflicts would not match the stated 'iff' with LR(1) or SLR(1) options.

  4. 4
    Step 4

    LR(1) may be conflict-free even when LALR(1 conflicts appear (due to lookahead merging/union), so (i) cannot be 'iff'. Similarly SLR(1)/SLR(0) approximations are not the right exact 'iff' counterpart to LALR(1).

Pro Tip

When a question asks for an iff relation between LALR(1) and another LR variant, focus first on the LR(0) core, because LALR(1) is defined by merging LR(1) states with the same LR(0) core.

Warning about Option Wording

Option (iv) says SLR(0), but standard grammar theory typically uses SLR(1) (SLR(0) is not the standard named variant). For correct LR-family interpretation, treat (iv) as referring to an SLR-style parser with coarse lookaheads; it still does not match the intended iff relationship.

Choosing the Correct Option

The question:

For grammar GG, shift–reduce conflicts are present in LALR(1) parser, if and only if which condition holds?

Using the structural argument about LR(0) core overlap and the definition of LALR(1 via LR(0) core merging, the correct selection is:

  • (ii) the LR(0) parser for GG has S–R conflicts

Conflict Persistence Intuition Across LR Variants

Core-overlap conflicts (LR(0)) persist into LALR(1). Lookahead precision (LR(1)) can avoid some conflicts that LALR(1 may create via merging.

Concept Checks (Frequently Confused Points)

Knowledge Check

Question 1 of 4
Q1Single choice

If a grammar GG has a shift–reduce conflict in its LR(0) parser, then its LALR(1) parser must also have a shift–reduce conflict. Which option captures the intended iff relationship?