GATE / CS ARCHIVE

GATE CSE 2022 / QUESTION 29

GATE CSE 2022 Q29

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

GATE 2022, Q29 1 mark · NAT
Report issue

Parsing & Syntax Analysis

Question 29, GATE 2022: Grammar: S′→S; S→S+R|R; R→R*P|P; P→(S)|id. Let I0={S′→S·, S→S·+R}. Count items in goto(closure(I0),+).
Tap to enlarge
Answer & solution

Official answer: 5

Step through it (3 steps)

Taking goto on + advances S→S·+R to S→S+·R. Closure then adds R→·R*P, R→·P, P→·(S), and P→·id. No dot precedes S in these items, so no further closure is needed. Total 5 items.

Closure only expands a nonterminal immediately after a dot. Initially the dots precede end-of-rule or terminal +, so closure(I0)=I0. After shifting +, R is exposed; recursively expanding R and P yields the five items listed. The left-recursive R production is added once, so closure terminates.

Original paper, page 22 · Answer key