Machine-translated by Google. Questions are authored in English.
Top

Discussion

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?

  • A.Only (I) is correct.
  • B.Only (II) is correct.
  • C.Both (I) and (II) are correct.
  • D.Neither (I) nor (II) is correct.

Answer: C

Both (I) and (II) are correct.

Backpatching solves the problem of generating jumps whose targets are not yet known. The compiler emits a jump with its target left blank, records the instruction in a list (such as truelist, falselist or nextlist), and fills in the target later, once the label is known.

This lets a one-pass translator generate short-circuit code for Boolean expressions, where 'true' and 'false' exits jump forward to code not yet generated (I). It equally handles flow-of-control statements such as if, if-else and while, whose exit and loop-back jumps are patched when the statement ends (II). The classic textbook treatment (Aho, Sethi and Ullman) uses it for both.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.