GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The grammar S → A B; A → a | ε; B → A b | c is not LL(1). Each change below is applied to it on its own. Which of them make the grammar LL(1)? I. Replace B → A b by B → b A. II. Replace B → A b by B → A c and B → c by B → b. III. Add the production B → ε. IV. Replace S → A B by S → B A.
- A. I only
- B. I, III and IV only
- C. I and IV only
- D. II and IV only
Correct answer: C. I and IV only
The original clash is M[A, a]: A → a, and A → ε because FOLLOW(A) ∋ a (from B → A b with A first in B). I: A is now followed only by FOLLOW(B) = {$}, so no clash. II: B → A c still puts FIRST(B) = {a, b, c} after A, so a ∈ FOLLOW(A): clash remains. III: B → ε adds $ to FOLLOW(A) but a is still there: clash remains. IV: A now ends the sentence (FOLLOW(A) = {$, b}), and a ∉ FOLLOW(A): LL(1).
More Compiler Design questions
- L is the set of strings over {a, b} such that in every prefix the number of a's and the number of b's differ by at most 2. How many states…
- A compiler generates jumping code by backpatching (each relation gives 'if r goto ' then 'goto ', numbering from 100) for: if (!(a < b) &&…
- Compute FIRST of every non-terminal of S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε, treating ε as a member of FIRST when the…
- For S → A b B | c; A → a | ε; B → c B | ε (augmented), in how many LR(0) states is there a conflict, and how many reduce entries does the…
- For S → A B | B C; A → a A | ε; B → b B | ε; C → c C | d, which statement is FALSE?
- 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…