GATE Computer ScienceHardGATE CS (PYQ pattern)
For the code 1: i = 0; 2: s = 0; 3: L1: if i >= n goto L4; 4: t = a + i; 5: if t > m goto L2; 6: s = s + t; 7: goto L3; 8: L2: a = a - 1; 9: L3: i = i + 1; 10: goto L1; 11: L4: return s, which definitions (named by statement number) reach the entry of statement 7 (goto L3)?
- A. 4, 6 and 9
- B. 1, 4, 6, 8 and 9
- C. 1, 2, 4, 6, 8 and 9
- D. 4, 6, 8 and 9
Correct answer: B. 1, 4, 6, 8 and 9
Statement 7 is reached only through 6, so the s-definition 2 is killed by 6 (s = s + t). For i, both 1 (first iteration) and 9 (around the back edge) reach, since nothing between them and 7 redefines i. t comes from 4; a's definition 8 reaches on the path 8 → 9 → 10 → 3 → 4 → 5 → 6 → 7. Hence {1, 4, 6, 8, 9}.
More Compiler Design questions
- An LR parser for S → ( L ) | x; L → S | L , S parses "( ( x , x ) , x , ( x ) )". How many reductions does it perform (accept not…
- Sethi–Ullman labelling: a leaf is 1 as a left child and 0 as a right child (a right operand may be a memory operand); an interior node is…
- Build the LL(1) table for E → T R; R → + T R | − T R | ε; T → F P; P → ^ T | ε; F → ( E ) | id (^ is right-associative exponent). How many…
- An LR parser for E → id | E [ E ] | ( E ) parses "id [ ( id [ id ] ) ]". What is the largest number of grammar symbols on its stack at any…
- S → ( S ) S | ε is both LL(1) and SLR(1). Both parsers process "( ( ) ( ) )". What is the largest number of grammar symbols on the LL(1)…
- Augment S → ( L ) | x; L → S | L , S with S′ → S and build the canonical collection of LR(0) item sets. How many states does it have, and…