GATE / CS ARCHIVE

GATE CSE 2006 / QUESTION 7

Canonical LR zero item sets

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

GATE 2006, Q7 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 7, GATE 2006: Grammar: S→S*E | E; E→F+E | F; F→id. Consider LR(0) items 1: S→S*·E; 2: E→F·+E; 3: E→F+·E. Which pair appears together in a canonical item set?
Options:
(A) 1 and 2
(B) 2 and 3
(C) 1 and 3
(D) None of these pairs
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

Step through it (12 steps)

1. The state after recognizing S* contains S→S*·E plus closure items E→·F+E,E→·F,F→·id. The item E→F·+E occurs after a transition on F, together with E→F·.

2. The item E→F+·E occurs after a further transition on +, again with the initial E/F closure. These three kernels are different states; closure does not introduce either of the other listed advanced items.

3. Thus none of the listed pairs coexist, D.

4. Teaching check: LR closure inserts productions with the dot at their beginning when a nonterminal follows the dot. It never advances an existing dot. Thus an item beginning E→·F can coexist with item 1, but the advanced E→F·+E requires a GOTO on F, producing another state.

Original paper, page 1