GATE Computer ScienceHardGATE CS (PYQ pattern)
The SLR(1) table of S → i E t S Z | a; Z → e S | ε; E → b has one shift-reduce conflict (shift e versus reduce Z → ε), resolved as yacc does by shifting. While parsing "i b t i b t a e a", what are the last four reductions, in order?
- A. Z → ε, S → i E t S Z, Z → e S, S → i E t S Z
- B. Z → e S, Z → ε, S → i E t S Z, S → i E t S Z
- C. Z → e S, S → i E t S Z, Z → ε, S → i E t S Z
- D. Z → ε, Z → e S, S → i E t S Z, S → i E t S Z
Correct answer: C. Z → e S, S → i E t S Z, Z → ε, S → i E t S Z
After the first a is reduced to S, the lookahead is e and the parser shifts it (the conflict choice), so the else is attached to the inner if: a → S, then Z → e S and the inner S → i E t S Z. Now the lookahead is $, so the outer if gets Z → ε, and finally the outer S → i E t S Z.
More Compiler Design questions
- 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…
- 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…