Practice free →
HomeGATE CSEcomputerscienceTheory of Computation › A LEFT-RECURSIVE rule in a CFG has the form $A \…

A LEFT-RECURSIVE rule in a CFG has the form $A \to A\alpha$ for some non-empty $\alpha$. Why is left recursion problematic?

AIt causes the grammar to be ambiguous
BTop-down LL parsers loop forever on it
CIt makes the grammar context-sensitive
DIt increases the language size to infinity
Answer & Solution
Correct answer: B. Top-down LL parsers loop forever on it
1. TOP-DOWN parsers (like LL(k) and recursive descent) attempt to MATCH a non-terminal by applying a production and recursively parsing the result. 2. For a rule $A \to A\alpha$: the parser tries to parse $A$ by parsing $A$ (which tries to parse $A$, which...) — an INFINITE LOOP. 3. SOLUTION: rewrite left recursion as right recursion. Replace $A \to A\alpha \mid \beta$ with $A \to \beta A'$ and $A' \to \alpha A' \mid \varepsilon$. This 'unrolls' the recursion to a form LL parsers can handle. 4. Bottom-up parsers (LR) DO handle left recursion natively (they build trees from the leaves up). 5. Option A is wrong — left recursion is independent of ambiguity. Option C and D are wrong. _Source: Jeff Erickson, "Models of Computation", §5.5 (Parsing CFGs, top-down vs bottom-up)._
Solve this in the app — GATE CSE practice & 24k+ MCQs →
Related questions