GATE / CS ARCHIVE

GATE CSE 2024 SET 2 / QUESTION 65

Compute an LR(0) GOTO closure

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2024 Set 2 paper

GATE 2024 Set 2, Q65 2 marks · NAT
Report issue

Parsing & Syntax Analysis

Question 65, GATE 2024: Augmented grammar: S′→S; S→SS | Aa | bAc | Bc | bBa; A→d#; B→@. Terminals are a,b,c,d,#,@. I0=CLOSURE({S′→·S}). For an SLR parser, how many items are in GOTO(I0,S)?
Tap to enlarge
Answer & solution

Official answer: 9

Step through it (3 steps)

Approach: Move dots over S only where S immediately follows the dot, then close the resulting item set.

1. Derivation. The initial closure contains S′→·S and S→·SS, plus the other four S-start items and A→·d#, B→·@. GOTO on S shifts the first two into S′→S· and S→S·S. The latter requires closure under S, adding all five S-start items: ·SS, ·Aa, ·bAc, ·Bc, ·bBa. Closure of their leading A/B adds A→·d# and B→·@. The total is 2+5+2=9 distinct LR(0) items; SLR FOLLOW sets do not change this item-set construction.

2. Explanation and checks. The full resulting set is S′→S·; S→S·S; S→·SS; S→·Aa; S→·bAc; S→·Bc; S→·bBa; A→·d#; B→·@. The item S→·SS does not generate endlessly many items: closure is a set and revisiting the same production adds no duplicate. Terminals b,d,@ do not cause further closure expansion. Both # and @ are explicitly terminals here, so neither denotes epsilon or the end marker. FOLLOW sets govern SLR reduction entries, not this GOTO construction.

Original paper, page 40 · Answer key