GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Available-expressions analysis (expressions compared textually, so a * b and b * a differ; assigning an operand kills an expression) is run on 1: t = a * b; 2: if c > 0 goto L1; 3: a = a + 1; 4: u = a * b; 5: goto L2; 6: L1: v = b * a; 7: w = a * b; 8: L2: x = a * b; 9: if x > n goto L3; 10: b = b + x; 11: goto L2; 12: L3: return x. How many expressions are available on entry to statement 8 (L2), and on entry to statement 12 (L3)?
- A. 1 and 1
- B. 2 and 1
- C. 0 and 1
- D. 0 and 0
Correct answer: C. 0 and 1
a * b reaches L2 recomputed on both forward paths (statement 4 after a changes, statement 7), but L2 is also entered from the back edge 11 → 8, and b = b + x in statement 10 kills a * b (and b * a). The meet is intersection, so nothing is available at 8. Statement 8 then recomputes a * b and nothing before L3 kills it, so exactly a * b is available at 12.
More Compiler Design questions
- Nested procedures: main (depth 1) contains A (depth 2); A contains B (depth 3); B contains C (depth 4). C also calls itself recursively…
- void p(int x, int y) { x = x + 1; y = y + x; } is called as p(a, a) with a = 2. What is a after the call when the parameters are passed by…
- How many distinct LR(0) items does the grammar E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id have (do not augment it…
- Dead-code elimination deletes every assignment whose target is not live immediately after it (live-variable analysis), and is repeated…
- Same function f(n) = 1 for n ≤ 2, else f(n − 1) + f(n − 2) + f(n − 3). Each activation record takes 28 bytes. What is the maximum stack…
- 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…