GATE Computer ScienceHardGATE CS (PYQ pattern)
For S′ → S; S → A A A; A → a A | b, how many states of the canonical LR(1) automaton contain the complete item A → b · ?
- A. 3
- B. 2
- C. 1
- D. 4
Correct answer: B. 2
The lookahead of an A is what can follow it: the first and second A are both followed by FIRST(A) = {a, b}, the third by $. The first two A's therefore reach the very same LR(1) states (same items, same lookaheads), so A → b· appears in one state with {a, b} and one with {$}: 2, not 3.
More Compiler Design questions
- int f(int k) { if (k <= 0) return 0; return g(k - 1) + 1; } int g(int k) { if (k <= 1) return 1; return f(k - 2) + f(k - 1); } During the…
- After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol…
- A DAG is built for r = (p − q) (p − q) + (q − p) (p − q) − (p − q), with commutative and − not commutative. How many interior (operator)…
- For the grammar S → C C; C → c C | d (augmented with S′), the canonical LR(1) automaton is built and then the states with identical LR(0)…
- Using the backpatching scheme (each relation gives 'if r goto ' then 'goto ', no fall-through optimisation, numbering from 100), the code…
- For the nested-loop code 1: s = 0; 2: i = 0; 3: L1: if i >= n goto L5; 4: j = 0; 5: L2: if j >= i goto L4; 6: s = s + j; 7: j = j + 1; 8…