GATE / CS ARCHIVE

GATE CSE 1999 / QUESTION 2.15

Both left and right recursion

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

GATE 1999, Q2.15 2 marks · MSQ
Report issue

Parsing & Syntax Analysis

Question 2.15, GATE 1999: A grammar is both left and right recursive for a nonterminal. Must it be ambiguous,unambiguous,or is more information required?
Tap to enlarge
Select all that apply
Answer & solution

Answer: C literally; usefulness assumptions matter (no official key was published)

Both recursion directions can certainly occur in an ambiguous grammar: S→Sa|aS|a derives aa using either recursive rule. But the premise alone does not say that the recursive nonterminal is reachable and productive. For example S→c together with A→Aa|aA|b has both recursion directions at A, while the start language has just one parse tree for c. Thus the literal premise does not force ambiguity, giving C. The example deliberately exposes the omitted usefulness condition; it does not assert that an arbitrary useful doubly recursive nonterminal is harmless. The usual ambiguity claim needs a more precise grammar hypothesis.

Original paper, page 5