GATE CS 2025 Set 2 | Question 21
Consider the following statements about the use of backpatching in a compiler for intermediate code generation:
(I) Backpatching can be used to generate code for Boolean expression in one pass.
(II) Backpatching can be used to generate code for flow-of-control statements in one pass.
Which ONE of the following options is CORRECT?
Explanation
Answer: (C)
In one-pass code generation, a jump is often emitted before the address it should jump to is known. Backpatching handles this: the jump is emitted with an empty target, its position is added to a list, and every jump on the list is filled in once the target becomes known.
- (I) is correct. For Boolean expressions with short-circuit evaluation, the jumps taken when the expression is true or false are collected in truelist and falselist and patched later.
- (II) is correct. If, if-else and while statements patch their jumps the same way, using these lists and a nextlist, without a second pass.
Answer: C