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 | ε.
- A. I only
- B. I, III and IV
- C. II and III only
- 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
- Consider this pseudo-code (arrays are 1-based): i = 1; a = [5, 6, 7]; procedure P(x, y) { x = x + 1; y = y 2; } P(i, a[i]); print(i, a[1]…
- A C-like scanner uses maximal munch with these tokens: identifiers (letters and digits, starting with a letter) and the operators ++…
- A generated scanner for the token set { a, abcd, b, c, d } always returns the longest accepting prefix, and if the DFA reaches the dead…
- A scanner generator is given the rules, in this order: (1) if → IF; (2) [a-z][a-z0-9] → ID; (3) [0-9]+ → NUM. It uses the longest match…
- The Thompson construction (Aho–Sethi–Ullman style: a symbol gets 2 states; union and star each add a new start and a new final state…
- In the Thompson NFA for (a|b), each symbol machine has 2 states and 1 non-ε edge; union and star add a new start and final state with 4…