GATE Computer ScienceHardGATE CSE · NIELIT
How many states does the canonical LR(0) automaton have for the augmented grammar S' → S, S → a S b | a b?
- A. 5
- B. 6
- C. 7
- D. 10
Correct answer: B. 6
States: I0; goto on S (S′→S·); goto on a (S→a·Sb, S→a·b plus closure); goto on S from there (S→aS·b); goto on b (S→ab·); goto on b from aS (S→aSb·). That is 6 distinct item sets (a on the a-state loops back to itself).
More Compiler Design questions
- Program: int x = 5; int f() { return x; } int g() { int x = 7; return f() + x; } int h() { int x = 11; return g() + f() + x; } main calls…
- The expression ((((a + b) + c) ((a + b) + d)) - ((a + b) ((a + b) + c))) is stored as a DAG with common subexpressions shared (no…
- Control-flow graph: B1: a=1; b=2; c=a+b; then B2: d=c+b; if d<10 goto B4 (else B3); B3: c=d+a; b=c; goto B2; B4: print(c+a). Edges: B1→B2…
- Let L = { w ∈ {a,b} : the 4th symbol from the right end of w is 'a' }. The minimal DFA for L has how many states (including any dead/trap…
- Procedure P(x, y) { x = x + 1; y = x + y; } is called as P(a, a) with a = 3. What is a after the call under call-by-reference, and under…
- Grammar: S → L = R | R; L → R | id; R → L (augmented with S' → S). How many states do the LR(0) automaton and the canonical LR(1)…