GATE Computer ScienceVery hardGATE CS (PYQ pattern)
G: S → a A d | b B d | a B e | b A e; A → c; B → c is LR(1) but not LALR(1). Which of these changes, each made on its own, makes the grammar LALR(1)? I. Replace B → c by B → c c. II. Replace S → b A e by S → b A f. III. Replace S → b B d by S → b B f.
- A. I and II only
- B. I, II and III
- C. I only
- D. II and III only
Correct answer: C. I only
After a c: A → c· on d, B → c· on e; after b c: B → c· on d, A → c· on e. Merging gives a reduce-reduce clash. I: B now needs a second c, so the two complete items never share a state. II: after b c it becomes A on f, B on d; merged A {d, f} and B {e, d} still collide on d. III: after b c, B on f, A on e; merged A {d, e}, B {e, f} collide on e.
More Compiler Design questions
- Sethi–Ullman labelling (a leaf is 1 if it is a left child and 0 if it is a right child, since a right operand may come from memory; an…
- An SDD uses N → B N1 { N.val = B.val + 2 × N1.val } | B { N.val = B.val } and B → 0 { B.val = 0 } | 1 { B.val = 1 }. What is N.val at the…
- A SLR(1) parser for the augmented grammar S → id | id [ E ] | id ( E ); E → id parses "id [ id ]". What is the maximum number of grammar…
- Partition into basic blocks (leaders: the first statement, every jump target, every statement right after a jump): 1: i = 0; 2: L1: if i >…
- Consider the strings over {a,b} that start and end with different symbols. How many states does the minimal complete DFA (including a dead…
- A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a…