GATE / CS ARCHIVE

GATE CSE 2016 SET 2 / QUESTION 45

GATE CSE 2016 Set 2 Q45

Compiler Design · Parsing & Syntax Analysis · Full GATE CSE 2016 Set 2 paper

GATE 2016 Set 2, Q45 2 marks · MCQ
Report issue

Parsing & Syntax Analysis

Question 45, GATE 2016: Which grammar has no left recursion? A S→AB,A→Aa|b,B→c; B S→Ab|Bb|c,A→Bd|ε,B→e; C S→Aa|B,A→Bb|Sc|ε,B→d; D S→Aa|Bb|c,A→Bd|ε,B→Ae|ε.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

Grammar B has an acyclic nonterminal dependency chain S→A/B, A→B, with B deriving only terminal e; it cannot derive a sentential form beginning again with the same nonterminal. A has direct A→Aa. C has S⇒Aa⇒Sca. D has A⇒Bd⇒Aed. Thus B alone is free of left recursion.

Left recursion means a derivation A⇒+Aα, possibly passing through other nonterminals and nullable productions. It is not the same as any recursion anywhere on a right side. In B every chain beginning in a nonterminal descends from S to A to B, and B immediately produces terminal e, so no cycle can return to its starting nonterminal.

Original paper, page 38 · Answer key