GATE Computer ScienceVery hardGATE CS (PYQ pattern)
S → A B; A → a | ε; B → A b | c generates exactly five strings, and its LL(1) table has one multiply-defined cell. If that cell is resolved by always choosing A → ε, how many of the five strings does the parser accept? (If it is resolved by choosing A → a instead, call the count k.)
- A. 2 (and k = 5)
- B. 3 (and k = 5)
- C. 2 (and k = 4)
- D. 5 (and k = 2)
Correct answer: A. 2 (and k = 5)
L = {b, ab, aab, c, ac}; the clash is M[A, a] (a ∈ FOLLOW(A) via B → A b). Choosing A → ε on lookahead a: for ab the first A gives ε, then B → A b and the inner A again gives ε, so b meets a: rejected; likewise aab and ac. Only b and c pass: 2. Choosing A → a: every string parses (ab as A = a, B = b), so k = 5.
More Compiler Design questions
- Consider an SDD where for A → B C the rules are: B.i = A.i + 1, C.i = B.s, A.s = C.s. Which statement is correct?
- Consider these claims about LR parsers. I. Merging LR(1) states with the same core can create a shift-reduce conflict that the canonical…
- Code: k = 3; m = k k; k = k + 1; p = k m; q = p - 36; s = q + z; r = s 1. Only r is live at the end and z is an input. After constant…
- A predictive translator uses E → T R; R → + { print('+') } T R | − { print('−') } T R | ε; T → num { print(num.val) }. (The print action…
- The grammar S → X Y Z; X → a X | ε; Y → b Y | X; Z → c | ε is not LL(1). How many distinct parse trees does the string "a a a c" have?
- Construct the SLR(1) parsing table of S → a S b S | b S a S | ε (augmented). In how many states of the SLR(1) automaton does the ACTION…