Chapter 8: Intermediate Code Generation

Example

Code for a < b or c < d and e < f

if a < b goto Ltrue

goto L1

L1: if c < d goto L2

goto Lfalse

L2: if e < f goto Ltrue

goto Lfalse

Ltrue:

Lfalse:

Code for a < b or c < d and e < f

It is equivalent to a<b or (c<d and e<f) by precedence of operators.

Code:

if a < b goto L.true

goto L1

L1 : if c < d goto L2

goto L.false

L2 : if e < f goto L.true

goto L.false

where L.true and L.false are the true and false exits for the entire expression.

(The code generated is not optimal as the second statement can be eliminated without changing the value of the code).