GATE CS 2025 Set 2 | Question 21

MCQ · 1 mark · −0.33

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?

  1. Option A: Only (I) is correct.
  2. Option B: Only (II) is correct.
  3. Option C: Both (I) and (II) are correct. (correct)
  4. Option D: Neither (I) nor (II) is correct.

Answer

(C)

Explanation

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