The GATE Grind

GATE 2010 CS (CS1) – Question 48

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

For the grammar S→aSa | bSb | c, which classification holds?

  1. LL(1) but not LR(1)
  2. LR(1) but not LL(1)
  3. Both LL(1) and LR(1)
  4. Neither LL(1) nor LR(1)

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (C) Both LL(1) and LR(1)

Explanation

The three alternatives have pairwise disjoint FIRST sets {a},{b},{c}; there are no ε-productions. One lookahead token uniquely selects the production, so the grammar is LL(1). Every LL(1) grammar is LR(1), hence C.

More Parsing and Syntax Analysis questions

All Parsing and Syntax Analysis questions →