GATE Computer ScienceHardGATE CS (PYQ pattern)
Partition into basic blocks (leaders: the first statement, every jump target, every statement right after a jump): 1: i = 0; 2: L1: if i > n goto L3; 3: i = i + 1; 4: goto L1; 5: x = 5; 6: y = x; 7: L3: return i. How many basic blocks and control-flow edges are there, and how many blocks are unreachable from the entry?
- A. 6 blocks, 6 edges, 2 unreachable
- B. 5 blocks, 5 edges, 1 unreachable
- C. 5 blocks, 4 edges, 1 unreachable
- D. 4 blocks, 4 edges, 0 unreachable
Correct answer: B. 5 blocks, 5 edges, 1 unreachable
Leaders: 1, 2 (target L1), 3 (after the conditional jump), 5 (after goto), 7 (target L3). Blocks {1}, {2}, {3, 4}, {5, 6}, {7}. Edges: {1}→{2}, {2}→{7}, {2}→{3,4}, {3,4}→{2}, and the fall-through {5,6}→{7}: 5 edges. Nothing jumps to 5 and {3,4} ends in goto, so {5, 6} is unreachable (its edge into {7} still exists in the graph).
More Compiler Design questions
- Consider the strings over {a,b} that start and end with different symbols. How many states does the minimal complete DFA (including a dead…
- A table-driven LL(1) parser for S → a S A | ε; A → b S | c parses "a a b a c c". Each expansion of a non-terminal and each match of a…
- For G: S → a A b | A a; A → a | ε (which generates a, aa, ab and aab), which statements are true? I. G is LL(2). II. G is LL(3). III. G is…
- Let G2: S → A A; A → a A | b and G3: S → A A A; A → a A | b. For each, how many more states does the canonical LR(1) automaton have than…
- A SLR(1) parser for the augmented grammar S → x A | y B; A → z S | ε; B → z S | w parses "x z y w". What is the maximum number of grammar…
- The control-flow graph of 1: if p > 0 goto L2; 2: L1: x = x + 1; 3: if x > n goto L3; 4: L2: y = y + x; 5: if y < m goto L1; 6: L3: return…