GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 55

Shift-reduce conflicts under LALR merging

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2008 paper

GATE 2008, Q55 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 55, GATE 2008: An LALR(1) parser for G has shift-reduce conflicts if and only if:

(A) Its SLR(1) parser has shift-reduce conflicts
(B) Its LR(1) parser has shift-reduce conflicts
(C) Its LR(0) parser has shift-reduce conflicts
(D) Its LALR(1) parser has reduce-reduce conflicts
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. The equivalence is with canonical LR(1), option B. An LALR state merges LR(1) states having the same LR(0) core and unions lookaheads. Suppose a merged state has a reduction A→α on lookahead a and a shift on a.
2. The reduction/lookahead pair came from some original LR(1) state. The shift item is in the shared LR(0) core, so it also occurred in that very original state. Thus the shift-reduce conflict already existed before merging.
3. Conversely a conflict in an original LR(1) state survives the merge. Merging can introduce reduce-reduce conflicts, but cannot create a new shift-reduce conflict. SLR/LR(0) may report conflicts avoided by finer LR(1) lookaheads.

Original paper, page 11