GATE / CS ARCHIVE

GATE CSE 2013 / QUESTION 40

Merging LR items for LALR parsing

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

GATE 2013, Q40 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 40, GATE 2013: Two LR(1) states have items X→c·X, X→·cX, X→·d; first has lookaheads c/d on all, second $. About merging them into LALR, which claims are false?1 cannot merge because lookaheads differ;2 merging creates shift/reduce conflict;3 merging creates reduce/reduce conflict;4 cannot merge because goto on c leads to different states. A1 only, B2 only, C1and4, Dallfour.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

The two LR(1) states have the same LR(0) core, so LALR construction merges them and unions the lookahead sets for each core item. Every displayed item still has symbols to the right of the dot. Consequently this merged state has no reduction action and can create neither a shift/reduce nor a reduce/reduce conflict there. Its equal-core goto states are likewise merged in the LALR construction. Each of the four asserted objections is false, so D.

LALR equivalence compares items after removing lookaheads, and the two displayed sets then match exactly. Unioning lookaheads gives{c, d,$} for each item. Shift actions depend on the symbol after the dot; none of these items has its dot at the end, so there is no reduce action to conflict with a shift or another reduction. Goto targets with equal cores are treated by the same merging rule. Different lookaheads and different original state numbers are not reasons to reject the merge.

Original paper, page 9 · Answer key