GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For G: S → a B | a C d; B → b | ε; C → b c, which statements are true? I. G is LL(2). II. G is LL(3). III. G is LR(0). IV. G is SLR(1).
- A. I, II and IV only
- B. II and IV only
- C. IV only
- D. II, III and IV only
Correct answer: B. II and IV only
With B → b, S → a B gives a b; S → a C d gives a b c d: both start with a b, so 2 symbols do not decide (not LL(2)); the third symbol ($ versus c) does, so LL(3). After a, the LR(0) state has B → · complete beside shifts on b, and after a b it has B → b· beside C → b·c: LR(0) conflicts. FOLLOW(B) = {$} contains neither b nor c, so SLR(1) resolves both.
More Compiler Design questions
- Construct the LL(1) table of S → A B c | B d; A → a A | ε; B → b B | A. Which option lists exactly the multiply-defined cells?
- An ε-NFA over {a, b} has states 0–4, start state 0 and accepting state 3, with moves δ(0, a) = {1}, δ(1, b) = {2}, δ(2, a) = {0, 3}, δ(3…
- For the code 1: i = 0; 2: s = 0; 3: L1: if i >= n goto L4; 4: t = a + i; 5: if t > m goto L2; 6: s = s + t; 7: goto L3; 8: L2: a = a - 1…
- An LR parser for S → ( L ) | x; L → S | L , S parses "( ( x , x ) , x , ( x ) )". How many reductions does it perform (accept not…
- Sethi–Ullman labelling: a leaf is 1 as a left child and 0 as a right child (a right operand may be a memory operand); an interior node is…
- Build the LL(1) table for E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id (^ is right-associative exponent). How many…