GATE Computer ScienceModerateGATE CS (PYQ pattern)
Consider these claims about LR parsers. I. Merging LR(1) states with the same core can create a shift-reduce conflict that the canonical LR(1) parser does not have. II. Merging can create a reduce-reduce conflict that canonical LR(1) does not have. III. The LALR(1) and SLR(1) automata have the same number of states as the LR(0) automaton. IV. Every LR(0) grammar is SLR(1).
- A. I, II and III only
- B. II and IV only
- C. II, III and IV only
- D. I, III and IV only
Correct answer: C. II, III and IV only
Merging cannot introduce shift-reduce conflicts (the shift items depend only on the core), but it can introduce reduce-reduce ones, as in S → a A d | b B d | a B e | b A e, A → c, B → c. SLR and LALR use the LR(0) core automaton, and LR(0) ⊂ SLR(1).
More Compiler Design questions
- 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?
- Construct the SLR(1) parsing table of S → a S b S | b S a S | ε (augmented). In how many states of the SLR(1) automaton does the ACTION…
- G1: S → A B; A → a A | c; B → a B | c. G2: S → A B A; A → a A | c; B → b B | c. For each, how many more states does the canonical LR(1)…
- The grammar S → ( S ) S | ε is both LL(1) and SLR(1). On the input "( ( ) ) ( )", how many times does the LL(1) parser expand S → ε, and…