GATE Computer ScienceHardGATE CS (PYQ pattern)

Which of the following grammars are LL(1)? (I) S → a S b | ε. (II) S → a S a | a. (III) S → A B, A → a | ε, B → a | b. (IV) S → a S | b S | ε.

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

Correct answer: D. I and IV only

I: FIRST(aSb) = {a} and FOLLOW(S) = {b, $}, so no conflict. II fails because both alternatives begin with a. III fails because A → ε must be used on FOLLOW(A) = {a, b}, which includes a, clashing with A → a. IV: FOLLOW(S) = {$} is disjoint from {a, b}, so it is LL(1).

More Compiler Design questions

Exams that ask this topic