GATE Computer ScienceHardGATE CS (PYQ pattern)

For S′ → S; S → A A A; A → a A | b, how many states of the canonical LR(1) automaton contain the complete item A → b · ?

  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

The lookahead of an A is what can follow it: the first and second A are both followed by FIRST(A) = {a, b}, the third by $. The first two A's therefore reach the very same LR(1) states (same items, same lookaheads), so A → b· appears in one state with {a, b} and one with {$}: 2, not 3.

More Compiler Design questions

Exams that ask this topic