GATE Computer ScienceVery hardGATE CS (PYQ pattern)
The standard algorithm removes all left recursion from S → A a | b; A → A c | S d | e, taking the non-terminals in the order S, A (substitute S into A, then remove A's immediate left recursion with a new A′). What are the A′-productions of the result, and is the result LL(1)?
- A. A′ → c A′ | a d A′ | ε; LL(1)
- B. A′ → c A′ | a d A′ | ε; not LL(1)
- C. A′ → c A′ | d A′ | ε; not LL(1)
- D. A′ → c A′ | ε; LL(1)
Correct answer: B. A′ → c A′ | a d A′ | ε; not LL(1)
Substituting S gives A → A c | A a d | b d | e. Removing immediate recursion: A → b d A′ | e A′; A′ → c A′ | a d A′ | ε (7 productions in all with S → A a | b). It is still not LL(1): S → A a and S → b both start with b (A → b d A′), and FOLLOW(A′) = FOLLOW(A) ∋ a clashes with A′ → a d A′.
More Compiler Design questions
- int i = 1; int A[0..2] = {5, 6, 7}; void f(x, y) { x = x + 1; y = 10; } The call f(i, A[i]) uses copy-in/copy-out (value-result), copying…
- For G: S → x S y | x y | S S, which statements are true? I. G is ambiguous. II. The canonical LR(1) table has more multiply-defined cells…
- A lexer uses longest match, breaking ties in favour of the rule listed first, with rules: KW = if | then; ID = [a-z][a-z0-9]; NUM =…
- G: S → id | id [ E ] | id ( E ); E → id. G′ is obtained from G by left factoring S. Which statements are true? I. G is LL(1). II. G′ is…
- Construct the SLR(1) parsing table of S → a B | b A; A → a | a S | b A A; B → b | b S | a B B (augmented). In how many states of the…
- An NFA over {a, b} has states 0 to 4, start state 0, and these moves (a missing move means no transition): δ(0,a)={1,2}; δ(0,b)={0,1,2}…