GATE Computer ScienceVery hardGATE CS (PYQ pattern)
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 y has blocks B0 = {1}, B1 = {2, 3}, B2 = {4, 5}, B3 = {6}. Using 'a back edge is an edge whose head dominates its tail', how many back edges and natural loops does it have?
- A. 1 back edge (B2 → B1) and 1 natural loop
- B. 2 back edges and 2 natural loops
- C. 1 back edge (B1 → B2) and 1 natural loop
- D. 0 back edges and 0 natural loops
Correct answer: D. 0 back edges and 0 natural loops
B0 jumps into the cycle B1 ⇄ B2 at both B1 (fall-through) and B2 (goto L2). So neither B1 dominates B2 nor B2 dominates B1 (both have idom B0). Neither cycle edge is a back edge, and natural loops are defined only from back edges: the graph is irreducible and has a cycle but no natural loop.
More Compiler Design questions
- For S → a S b | a b | ε (augmented), how many multiply-defined ACTION cells do the SLR(1), LALR(1) and canonical LR(1) tables have, in…
- 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…
- 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…