GATE / CS ARCHIVE

GATE CSE 2012 / QUESTION 53

Predictive-table conflicts in a non-LL(1) grammar

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

GATE 2012, Q53 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 53, GATE 2012: Grammar: S→aAbB | bAaB | ε; A→S; B→S. S is the start symbol. The partial predictive table has columns a,b,$: S row=[E1,E2,S→ε]; A row=[A→S,A→S,error]; B row=[B→S,B→S,E3]. ε is empty and $ is the input-end marker.
Fill E1,E2,E3.
(A) E1={S→aAbB,A→S}; E2={S→bAaB,B→S}; E3={B→S}.
(B) E1={S→aAbB,S→ε}; E2={S→bAaB,S→ε}; E3={S→ε}.
(C) E1={S→aAbB,S→ε}; E2={S→bAaB,S→ε}; E3={B→S}.
(D) E1={A→S,S→ε}; E2={B→S,S→ε}; E3={B→S}.
Question 53, GATE 2012: Grammar: S→aAbB | bAaB | ε; A→S; B→S. S is the start symbol. The partial predictive table has columns a,b,$: S row=[E1,E2,S→ε]; A row=[A→S,A→S,error]; B row=[B→S,B→S,E3]. ε is empty and $ is the input-end marker.
Fill E1,E2,E3.
(A) E1={S→aAbB,A→S}; E2={S→bAaB,B→S}; E3={B→S}.
(B) E1={S→aAbB,S→ε}; E2={S→bAaB,S→ε}; E3={S→ε}.
(C) E1={S→aAbB,S→ε}; E2={S→bAaB,S→ε}; E3={B→S}.
(D) E1={A→S,S→ε}; E2={B→S,S→ε}; E3={B→S}.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

For M[S, a], FIRST(aAbB) supplies S→aAbB; because a belongs to FOLLOW(S), the nullable alternative also supplies S→ε. Similarly M[S, b] contains both S→bAaB and S→ε. At M[B,$], B→S is inserted because S is nullable and $ belongs to FOLLOW(B). Thus E1={S→aAbB, S→ε}, E2={S→bAaB, S→ε}, E3={B→S}, exactly C. The two multiple-production cells are FIRST/FOLLOW conflicts, proving this grammar is not LL(1). The source’s phrase “LL(1) parsing table” should be understood as the table-construction procedure, not as certification that the grammar admits deterministic LL(1) parsing.

Check: Each parsing-table row can contain only productions whose left-hand side is that row’s nonterminal. This immediately eliminates options inserting A→S or B→S into S’s row, and eliminates S→ε as the B-row entry E3.

Original paper, page 15 · Answer key