GATE / CS ARCHIVE

GATE CSE 2021 SET 2 / QUESTION 51

GATE CSE 2021 Set 2 Q51

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

GATE 2021 Set 2, Q51 2 marks · NAT
Report issue

Parsing & Syntax Analysis

Question 51, GATE 2021: Augmented grammar S′→S; S→S#cS | SS | S@ | <S> | a | b | c. I0=CLOSURE({S′→·S}). Count LR(0) items in GOTO(GOTO(I0,<),<).
Tap to enlarge
Answer & solution

Official answer: 8

Step through it (4 steps)

On reading < from the initial closure the kernel is S→<·S>. Its closure adds all seven S productions with the dot at the beginning: S→·S#cS, ·SS, ·S@, ·<S>, ·a, ·b, ·c. Reading a second < reproduces exactly the same kernel and closure. Thus GOTO(GOTO(I0,<),<) has 1+7=8 items; the augmented S-prime item is not added because closure expands only S.

The resulting item set is {S→<·S>, S→·S#cS, S→·SS, S→·S@, S→·<S>, S→·a, S→·b, S→·c}. Recursive closure does not create infinitely many copies: items are set members. In particular, productions beginning with S are added once and their expansion adds no new productions beyond the seven already present.

Original paper, page 86 · Answer key