GATE Computer ScienceHardGATE CS (PYQ pattern)
In 1: i = 0; 2: L1: if i >= n goto L3; 3: i = i + 1; 4: if i > k goto L1; 5: j = j + i; 6: goto L1; 7: L3: return j, how many back edges does the control-flow graph have, and how many basic blocks are in the loop obtained by merging the natural loops that share a header?
- A. 1 back edge; 3 blocks
- B. 2 back edges; 3 blocks
- C. 2 back edges; 2 blocks
- D. 2 back edges; 4 blocks
Correct answer: B. 2 back edges; 3 blocks
Blocks: {1}, {2} (header L1), {3, 4}, {5, 6}, {7}. Both the conditional jump at 4 and the goto at 6 return to L1, and L1 dominates both tails: 2 back edges. Their natural loops are {L1, {3,4}} and {L1, {3,4}, {5,6}}; with a common header they are merged into one loop of 3 blocks ({1} and {7} are outside).
More Compiler Design questions
- An SLR(1) shift-reduce parser for E → T E'; E' → + T E' | ε; T → F T'; T' → F T' | ε; F → ( E ) | id parses "id + id id". Each shift and…
- Backpatching scheme (each relation gives 'if r goto ' and 'goto ', no fall-through optimisation, instruction numbers from 100). How many…
- A basic block compiles to six three-address statements: t1 = a + b; t2 = c d; t3 = a + b; t4 = t1 t2; t5 = t3 − t4; x = t5. Value…
- After applying left factoring repeatedly (each time extracting the longest common prefix of alternatives that share a first symbol…
- Consider the grammar S → A B c, A → a A | ε, B → b B | A d | ε. How many terminals are in FOLLOW(A), and is the grammar LL(1)?
- For the grammar S → A B, A → a A | a, B → b, the augmented canonical LR(0) collection has how many states, and what is the strongest class…