GATE / CS ARCHIVE

GATE CSE 1992 / QUESTION 3(i)

A recursive macro that fails to progress

Compiler Design · Compiler Phases, Linking & Loading · Full GATE CSE 1992 paper

GATE 1992, Q3(i) Descriptive
Report issue

Compiler Phases, Linking & Loading

Question 3(i), GATE 1992: M1 calls M1(X+1) when X=0 and otherwise emits WORD X; M2 calls M2(X) when X=0 and otherwise emits WORD X+1. Which loops forever, and give a call.
Question 3(i), GATE 1992: M1 calls M1(X+1) when X=0 and otherwise emits WORD X; M2 calls M2(X) when X=0 and otherwise emits WORD X+1. Which loops forever, and give a call.
Tap to enlarge
Answer & solution

Answer: M2 0 (no official key was published)

For M1 0, the recursive invocation receives 1. Its zero test fails, so it emits a word and stops; a nonzero initial argument likewise stops directly. In M2 0, the recursive call receives exactly 0 again, so every expansion repeats the same zero test and invocation with no progress. This causes unbounded expansion until a practical processor limit intervenes. The nonzero WORD branch cannot rescue that call because it is never reached. The analysis assumes expansion-time arithmetic and equality tests on X as intended.

Original paper, page 4