GATE / CS ARCHIVE

GATE CSE 2005 / QUESTION 14

Predictive parsing and two grammar defects

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

GATE 2005, Q14 1 mark · MCQ
Report issue

Parsing & Syntax Analysis

Question 14, GATE 2005: Grammar A→AA|(A)|ε is unsuitable for predictive parsing because it is: A ambiguous; B left-recursive; C right-recursive; D an operator grammar. Assess the nonunique objections rather than forcing one choice.
Tap to enlarge
Your answer
Answer & solution

Answer: Both A and B are valid objections (no official key was published)

The production A→AA is directly left-recursive, so a naive predictive recursive-descent parser can recur indefinitely before consuming input; this is B. The same grammar is also ambiguous: ε has the distinct derivations A→ε and A→AA→εA→ε, giving different parse trees. An ambiguous grammar cannot be LL(1), so A is also a valid reason. Therefore the single-choice wording does not uniquely distinguish these two objections. Right recursion alone is not a barrier to predictive parsing.

The production A→AA begins with the same nonterminal, so direct predictive expansion can recurse without consuming input. Independently, ε has distinct parse trees A⇒ε and A⇒AA⇒εε, demonstrating ambiguity. A grammar with these properties cannot be LL(1), making both A and B valid reasons in the literal single-choice wording. Right recursion alone is not an objection to predictive parsing, and adjacent nonterminals also prevent the standard operator-grammar restriction.

Original paper, page 2