Control-Flow Translation of Boolean Expressions
Introduction: A boolean expression is an expression that results in a boolean value, that is, in a value of either true or false.
A Boolean expression B is translated into three-address instructions that evaluate B using conditional and unconditional jumps to one of two labels:
B.true if B is true, and B.false if B is false.
The fourth production in Fig. 6.37, B E\ rel E2, is translated directly into a comparison three-address instruction with jumps to the appropriate places. For instance, B of the form a < b translates into:
if a < b goto B.true
The remaining productions for B are translated as follows:
- Suppose B is of the form f?i I I B2. If Bi is true, then we immediately know that B itself is true, so Bi.true is the same as B.true. If Bi is false, then B2 must be evaluated, so we make Bi.false be the label of the first instruction in the code for B2. The true and false exits of B2 are the same as the true and false exits of B, respectively.
- The translation of B1 kk B2 is similar.
- No code is needed for an expression B of the form \Bi. just interchange the true and false exits of B to get the true and false exits of B±.
- The constants t r u e and false translate into jumps to B.true and B.false, respectively.