The GATE Grind

GATE 2016 CS (CS2) – Question 55

Compiler Design · Parsing and Syntax Analysis · 2 marks · Multiple choice

Which grammar has no left recursion?

  1. S → AB; A → Aa | b; B → c
  2. S → Ab | Bb | c; A → Bd | ε; B → e
  3. S → Aa | B; A → Bb | Sc | ε; B → d
  4. S → Aa | Bb | c; A → Bd | ε; B → Ae | ε

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) S → Ab | Bb | c; A → Bd | ε; B → e

Explanation

A has direct A→Aa. C has the indirect cycle S⇒Aa⇒Sca. D has A⇒Bd⇒Aed. In B, expansion moves only from S to A/B, then A to B and B to a terminal; no nonterminal can return as its own leftmost symbol. Thus B has no left recursion.

More Parsing and Syntax Analysis questions

All Parsing and Syntax Analysis questions →