Skip to content
Official PYQ · 2025

GATE CS 2025 Set 2 Q11 — Intermediate Code Generation

Explain with AI

​​​​Consider the following statements about the use of backpatching in a compiler for intermediate code generation:

  1. Backpatching can be used to generate code for Boolean expression in one pass.
  2. Back[atching can be used to generate code for flow-of-control statements in one pass.
Which ONE of the folloeing options is CORRECT?
Choose one option
View worked solution

Answer: C

Backpatching is a technique used in one-pass compilers to generate intermediate code for boolean expressions and flow-of-control statements without requiring a separate pass to resolve forward jumps.

Let us analyze both statements:

  • Statement I: When generating code for Boolean expressions (especially with short-circuit evaluation), conditional jumps are generated. Since the target addresses of these jumps (such as where to jump if the expression is true or false) are often not known at the time the jump instruction is generated, backpatching maintains lists of these incomplete instructions (truelist and falselist). These lists are filled in (backpatched) as soon as the target labels become known. Thus, Boolean expression code can be generated in a single pass. (Statement I is correct)

  • Statement II: Similarly, for flow-of-control statements (such as if-then, if-then-else, and while loops), forward jumps to the end of blocks or to the loop headers are required. Backpatching uses lists like nextlist to record these incomplete jumps and patches the target addresses once the end of the block or the next statement is parsed. This allows flow-of-control code generation in a single pass. (Statement II is correct)

Since both Statement I and Statement II are correct, the correct option is C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Intermediate Code Generation questions