GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The grammar S → S a b | S c | A S | x; A → A d | S y | z is transformed by the standard algorithm that removes (indirect and immediate) left recursion, processing the non-terminals in the order S, A and substituting earlier non-terminals into later ones. How many productions does the resulting grammar have? (Count each alternative, including A′ → ε, as one production.)
- A. 13
- B. 7
- C. 11
- D. 10
Correct answer: D. 10
Resulting grammar: S → A S S' | x S'; A → x S' y A' | z A'; S' → a b S' | c S' | ε; A' → d A' | S S' y A' | ε. That is 10 productions.
More Compiler Design questions
- 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…
- 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).
- 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…