GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 57

LL(1) classification from disjoint FIRST sets

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

GATE 2003, Q57 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 57, GATE 2003: Consider S→CC and C→cC | d. This grammar is:
A. LL(1)
B. SLR(1) but not LL(1)
C. LALR(1) but not SLR(1)
D. LR(1) but not LALR(1)
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step through it (2 parts)

1. C generates zero or more c symbols followed by d. Its alternatives begin with distinct terminal symbols: FIRST(cC)={c} and FIRST(d)={d}.
2. Neither C alternative is nullable, so no FIRST/FOLLOW overlap can create a second entry in its parsing-table cells. Put C→cC under c and C→d under d.
3. S has only one production; under either c or d use S→CC. No table cell has two choices. Thus one lookahead symbol always selects a production and the grammar is LL(1), A.

Solution: For C→cC|d the alternatives have disjoint FIRST sets {c} and {d}, and neither can derive ε. S has only its single production S→CC. Therefore every predictive-table cell has at most one production and the grammar is LL(1), option A. No stronger bottom-up distinction is needed.

Original paper, page 8