Consider the following statements about the use of backpatching in a compiler…
2025
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 expressions 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?
- A.
Only (I) is correct.
- B.
Only (II) is correct.
- C.
Both (I) and (II) are correct.
- D.
Neither (I) nor (II) is correct.
Attempted by 91 students.
Show answer & explanation
Correct answer: C
Answer: Both (I) and (II) are correct.
Backpatching postpones filling in jump targets until the target instruction address becomes known. During code generation, the compiler emits jump instructions with blank targets and maintains lists of those incomplete jumps.
For Boolean expressions, backpatching uses lists such as truelist and falselist. These lists allow the compiler to emit conditional jumps in one pass and patch their target addresses later.
For flow-of-control statements, backpatching is also used in one-pass intermediate-code generation. Constructs such as if-then, if-then-else, and while statements use lists such as nextlist, truelist, and falselist so that forward jumps can be patched when their targets are known.
Therefore, statement (I) is true and statement (II) is also true.
Correct Answer: Option C.
A video solution is available for this question — log in and enroll to watch it.