GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 21

GATE CSE 2025 Set 2 Q21

Compiler Design · Intermediate Code · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q21 1 mark · MCQ
Report issue

Intermediate Code

Question 21, GATE 2025: For compiler intermediate-code generation, consider: I. backpatching can generate code for Boolean expressions in one pass; II. backpatching can generate code for flow-of-control statements in one pass. Which is correct?
Options: A. I only; B. II only; C. both; D. neither.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

A branch target may not be known when its branch instruction is first generated. Backpatching emits the instruction with a placeholder target and records its location on a list. Later, when the target's instruction address becomes known, the compiler fills that field without rereading the source.

For a Boolean expression such as a<b && c<d, the compiler can keep true and false lists. A true branch from the first comparison is patched to the start of the second comparison; the final true/false branches are patched to the enclosing statement's destinations. This supports short-circuit Boolean code in one pass, so I is true.

For an if, while, or similar statement, next lists and branch lists are patched when the following block, loop test, or exit becomes known. Thus flow-of-control code can also be generated in one pass, making II true. “One pass” does not prohibit editing previously emitted target fields; that editing is precisely the role of backpatching. Answer: C.

Original paper, page 18 · Answer key