GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 60

SLR canonical LR and LALR state counts

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

GATE 2005, Q60 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 60, GATE 2005: For S→(S)|a, let n1, n2, n3 count SLR(1), canonical LR(1), LALR(1) states. In GFG: A n1<n2<n3; B n1=n3<n2; C n1=n2=n3; D n1=n3=n2 (duplicated equality as reproduced). Determine the actual counts independently; alternate distractor ordering differs.
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

For augmented S′→S and S→(S)|a, LR(0) has six states with kernels S′→·S, S′→S·, S→(·S), S→a·, S→(S·), and S→(S)· (including closures). Canonical LR(1) separates the inner/non-inner versions with lookaheads ) and $, yielding ten states. Merging identical LR(0) cores gives six LALR states again. Therefore n1=n3<n2, B.

SLR states are LR(0) item-set states, so its FOLLOW-based action construction does not add states. The six cores are listed in the baseline derivation. Canonical LR(1) retains context: an expression enclosed by parentheses must expect a closing parenthesis, whereas the outer expression expects end-of-input, creating extra versions of cores and ten states. LALR merges versions sharing the same LR(0) core, restoring six. Therefore 6=6<10 in the order n1, n3, n2.

Original paper, page 7