GATE Computer ScienceVery hardGATE CS (PYQ pattern)
For G: S → a A | b B; A → c A d | ε; B → c B d d | ε, which statements are true? I. G is LL(1). II. G is LR(0). III. The canonical LR(1) automaton has exactly 7 more states than the LALR(1) automaton.
- A. I and III only
- B. III only
- C. I, II and III
- D. I and II only
Correct answer: A. I and III only
I: FIRST(c A d) = {c} and FOLLOW(A) = {d, $} are disjoint (same for B), so LL(1). II: the state after a holds A → ·c A d and the complete item A → ·, a shift-reduce clash for LR(0). III: LR(0)/LALR have 13 states. In LR(1) seven cores split into a copy for the outermost A/B (lookahead $) and one for nested ones (lookahead d): after c for A and for B, c A·d, c A d·, c B·d d, c B d·d, c B d d·. That gives 20 states: 20 − 13 = 7.
More Compiler Design questions
- A scanner has two token rules, R1 = a b and R2 = b c. It always takes the longest prefix matching some rule and never backtracks over a…
- Register allocation by graph colouring is done on the loop 1: L1: v1 = v4 + 1; 2: v2 = v5 + 1; 3: v3 = v1 + 1; 4: v4 = v2 + 1; 5: v5 = v3…
- An array is declared A[L..10][−4..5] with 4-byte elements and stored in row-major order starting at address 1744. If the address of…
- For S → a A | b B; A → c A d | ε; B → c B d d | ε (augmented with S′ → S), count the reduce entries (state, terminal) in the ACTION…
- S → C C; C → c C | d is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column…
- For S → A b | B c; A → a A | ε; B → a B | ε (augmented), in how many LR(0) states is there a conflict, how many ACTION cells of the LR(0)…