GATE Computer ScienceHardGATE CS (PYQ pattern)
For S → id | id [ E ] | id ( E ); E → id (augmented with S′ → S), how many states do the LR(0) and the canonical LR(1) automata have?
- A. 10 and 10
- B. 9 and 11
- C. 10 and 11
- D. 11 and 13
Correct answer: C. 10 and 11
LR(0): I0, S′ → S·, the state after id (S → id·, S → id·[E], S → id·(E)), after [, after (, E → id· (one state, reached from both), S → id[E·], S → id(E·), S → id[E]·, S → id(E)·: 10. In LR(1) the item E → id· has lookahead ] after [ and ) after (, so that state splits in two: 11. Every other core occurs in a single context.
More Compiler Design questions
- The grammar S → A B; A → a A | a; B → a B | a is ambiguous. How many distinct parse trees does the string "a a a a a a" have?
- For the declaration grammar D → T L; T → int | float; L → L , id | id (augmented with D′ → D), how many states does the LR(0) automaton…
- Build the SLR(1) table of S → A a | b A c | d c | b d a; A → d (augmented). Which option describes all of its conflicts?
- Compute FIRST of every non-terminal of S → A B | B C; A → a A | ε; B → b B | ε; C → c C | c, treating ε as a member of FIRST when the…
- With int i = 2 and the array A = [0, 3, 5, 7, 9, 11, 13] (indices from 0), the call f(A[i], i) is made to void f(p, q) { i = i + 1; p = p…
- How many states does the minimal complete DFA (dead state included) for the regular expression (ab | aba) over {a, b} have?