GATE Computer ScienceHardGATE CS (PYQ pattern)

For E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id, compute FOLLOW of every non-terminal ($ counts as a member). What is the sum of the sizes of the five FOLLOW sets?

  1. A. 15
  2. B. 17
  3. C. 13
  4. D. 19

Correct answer: B. 17

FOLLOW(E) = {$, )} = FOLLOW(R). FOLLOW(T) = {+, −} ∪ FOLLOW(R) = {+, −, $, )}. P → ^ T gives FOLLOW(T) ⊇ FOLLOW(P) and T → F P gives FOLLOW(P) ⊇ FOLLOW(T), so FOLLOW(P) = FOLLOW(T). FOLLOW(F) = {^} ∪ FOLLOW(T) (P nullable) = 5 symbols. Sum 2 + 2 + 4 + 4 + 5 = 17.

More Compiler Design questions

Exams that ask this topic