GATE Computer ScienceModerateGATE CS (PYQ pattern)

An LL(1) parser for S → A B C; A → a A | ε; B → b B | ε; C → c | ε reads the input "a b a c". At the moment it first detects the syntax error, what is on top of its stack and what has been matched?

  1. A. C on top, after matching a b
  2. B. A on top, after matching a
  3. C. $ on top, after matching a b a
  4. D. B on top, after matching a b

Correct answer: D. B on top, after matching a b

S → A B C, A → a A, match a. With lookahead b, M[A, b] = A → ε (b ∈ FOLLOW(A)). M[B, b] = B → b B, match b. Now B is on top with lookahead a: FOLLOW(B) = {c, $} and FIRST(B) = {b}, so M[B, a] is blank: the error is found with B on top after a b were matched.

More Compiler Design questions

Exams that ask this topic