GATE / CS ARCHIVE

GATE CSE 2003 / QUESTION 16

Limits of LL-one grammar transformations

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

GATE 2003, Q16 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 16, GATE 2003: Which transformation suffices to turn an arbitrary context-free grammar into an LL(1) grammar? A. Removing left recursion alone; B. Left factoring alone; C. Both removing left recursion and left factoring; D. None of these.
Tap to enlarge
Your answer
Answer & solution

Answer: D (no official key was published)

1. LL(1) requires a deterministic choice of production from one lookahead symbol. Factoring resolves shared prefixes and removing left recursion removes an immediate predictive-parsing obstacle; neither establishes the required disjoint prediction sets in all grammars. In particular LL(1) cannot describe every context-free language.

2. Removing left recursion and left factoring remove common obstacles but do not make every CFG LL(1). Inherently ambiguous CFLs have no unambiguous grammar, whereas every LL(1) grammar is unambiguous; some unambiguous CFLs also are not LL(1). Thus none of the proposed transformations suffices for an arbitrary CFG, D.

Original paper, page 2