GATE Computer ScienceHardGATE CS (PYQ pattern)
For E → id | E [ E ] | ( E ) (augmented), how many states does the LR(0) automaton have, and which is the strongest of LR(0) / SLR(1) / LALR(1) that the grammar satisfies?
- A. 9 states; SLR(1) but not LR(0)
- B. 11 states; LALR(1) but not SLR(1)
- C. 9 states; it is LR(0)
- D. 8 states; SLR(1) but not LR(0)
Correct answer: C. 9 states; it is LR(0)
States: I0, E′ → E· (with E → E·[E]), E → id·, E → (·E), E → E[·E], E → (E·) with E → E·[E], E → E[E·] with E → E·[E], E → (E)·, E → E[E]·: 9. The only complete items (id·, (E)·, E[E]·) are alone in their states and the accept item sits only with a shift on [, so there is no conflict even without lookahead: the grammar is LR(0).
More Compiler Design questions
- 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…
- 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?