Consider the following statements about the use of backpatching in a compiler for intermediate code generation:
- Backpatching can be used to generate code for Boolean expression in one pass.
- Back[atching can be used to generate code for flow-of-control statements in one pass.
Which ONE of the folloeing options is CORRECT?
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 (
truelistandfalselist). 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, andwhileloops), forward jumps to the end of blocks or to the loop headers are required. Backpatching uses lists likenextlistto 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.
