GATE Computer ScienceHardGATE CS (PYQ pattern)

A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a terminal is one move. How many moves does it make until both stack and input hold only $, and how many of the expansions use S → ε?

  1. A. 14 moves, 3 of them S → ε
  2. B. 12 moves, 2 of them S → ε
  3. C. 14 moves, 2 of them S → ε
  4. D. 16 moves, 4 of them S → ε

Correct answer: C. 14 moves, 2 of them S → ε

FOLLOW(S) = {b, c, $}. Trace: S→aSA, a, S→aSA, a, S→ε (lookahead b), A→bS, b, S→aSA, a, S→ε (lookahead c), A→c, c, A→c, c. That is 8 expansions + 6 matches = 14 moves, with S → ε used twice.

More Compiler Design questions

Exams that ask this topic