GATE Computer ScienceEasyGATE CS (PYQ pattern)
How many distinct LR(0) items does the grammar E → E + T | T; T → T * F | F; F → ( E ) | id have (do not augment it; an ε-production gives exactly one item)?
- A. 20
- B. 18
- C. 12
- D. 19
Correct answer: B. 18
A production with right side of length m gives m + 1 items (dot positions); summing over the 6 productions gives 18.
More Compiler Design questions
- int f(int n) { if (n <= 2) return 1; return f(n − 1) + f(n − 2) + f(n − 3); } How many calls to f (including the first) does f(8) make as…
- For S → A B; A → a A | ε; B → b B | ε (augmented), in how many states of the LR(0) automaton is there a conflict, and is the grammar SLR(1)?
- With the Sethi–Ullman labelling (a left leaf is 1, a right leaf is 0 because it can be a memory operand; an interior node is max(l1, l2)…
- For S → S ( S ) | ε (augmented with S′ → S), how many states do the LR(0) and canonical LR(1) automata have?
- Consider G: S → A | x b; A → a A b | B; B → x. Which statements are true? I. G is LL(1). II. G is LR(0). III. G is SLR(1). IV. G is LALR(1).
- In the code 1: a = 4; 2: b = n 2; 3: i = 0; 4: L1: t1 = a b; 5: t2 = t1 + 8; 6: t3 = i a; 7: t4 = t2 + t3; 8: c = t1 - 3; 9: t5 = c + t2…