GATE Computer ScienceHardGATE CS (PYQ pattern)

In S → A B; A → a | ε; B → A b | c, FOLLOW(A) does not contain $. Which of these productions, each added to the grammar on its own, put $ into FOLLOW(A)? I. B → ε. II. B → b A. III. A → b A. IV. B → A B.

  1. A. I and II only
  2. B. I only
  3. C. I, II and IV only
  4. D. II and III only

Correct answer: A. I and II only

$ ∈ FOLLOW(S) = FOLLOW(B). I: B nullable makes A end S → A B. II: A ends B, so FOLLOW(B) ⊆ FOLLOW(A). III only adds FOLLOW(A) to itself. IV: A is followed by B, which is still not nullable, so only FIRST(B) is added.

More Compiler Design questions

Exams that ask this topic