GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For the augmented grammar S′ → S; S → ( L ) | x; L → S | L , S, how many states does the canonical LR(1) automaton have, and in how many of them is S → x · the complete item?
- A. 9 states, 1 with S → x ·
- B. 13 states, 3 with S → x ·
- C. 15 states, 2 with S → x ·
- D. 13 states, 2 with S → x ·
Correct answer: D. 13 states, 2 with S → x ·
Outside any parentheses an S is followed by $; inside, by ) or , (one lookahead set {), ,}, both at the first level and deeper). So the cores reachable from inside a ( (S → (·L), S → x·, S → (L·), S → (L)·) appear twice, once with $ and once with {), ,}, while the L-cores occur only inside: 9 LR(0) states + 4 extra = 13, and S → x· appears with $ and with {), ,}: 2 states.
More Compiler Design questions
- G: S → T | S ; T; T → a | ( S ). Removing the left recursion gives G′: S → T R; R → ; T R | ε; T → a | ( S ). Which statements are true?…
- The grammar A → B a | A a | c; B → B b | A b | d is transformed by the standard algorithm that removes (indirect and immediate) left…
- SDD: D → T L { L.inh = T.type }; T → int { T.type = integer }; L → L1 , id { L1.inh = L.inh; addType(id.entry, L.inh) }; L → id {…
- Which of the following are true? I. Every LL(1) grammar is LR(1). II. Every LL(1) grammar is LALR(1). III. Every LALR(1) grammar is LR(1)…
- Available-expressions analysis (expressions compared textually, so a b and b a differ; assigning an operand kills an expression) is run on…
- Nested procedures: main (depth 1) contains A (depth 2); A contains B (depth 3); B contains C (depth 4). C also calls itself recursively…