GATE Computer ScienceHardGATE CS (PYQ pattern)
Expressions are compared textually (x + y and y + x are different) and an assignment to an operand kills an expression. For 1: a = x + y; 2: if a > 0 goto L1; 3: b = y + x; 4: x = 1; 5: c = x + y; 6: goto L2; 7: L1: d = x + y; 8: L2: e = x + y; 9: return e, which expressions are available on entry to statement 8 (L2)?
- A. {x + y, y + x}
- B. ∅, since x = 1 kills x + y
- C. {y + x}
- D. {x + y}
Correct answer: D. {x + y}
Through L1: x + y is computed at 1 and 7 and nothing kills it. Through 3–6: y + x is computed at 3 but killed by x = 1 at 4 (x + y as well), yet statement 5 recomputes x + y after the kill. The meet over both paths leaves {x + y}, so e = x + y at statement 8 can reuse a temporary.
More Compiler Design questions
- For S → A a | b A c | B c | b B a; A → d; B → d (augmented), how many states do the LR(0) and canonical LR(1) automata have, and what does…
- The grammar S → S S S | a is ambiguous. How many distinct parse trees do the strings a⁷ (seven a's) and a⁶ (six a's) have, respectively?
- Build the SLR(1) table of the ambiguous grammar E → E + E | E E | id (augmented with S′ → E). How many LR(0) states are there, and how…
- For S → A a A b | B b B a; A → ε; B → ε (augmented), how many ACTION cells are multiply defined in the LR(0), SLR(1) and LALR(1) tables…
- For G: S → a A c | a B d | B c; A → z; B → z, which statements are true? I. The canonical LR(1) automaton has the same number of states as…
- S → a S | b S | c is LR(0). In its LR(0) parsing table the reduce action for a complete item is written in every terminal column including…