Three Address Code Generations for Boolean Functions By

Three Address Code Generations for Boolean Functions By : Arindam Khan

Intoduction: • • • Boolean expressions : composed of the Boolean operators (and, or, and not) applied to Boolean variables or relational expressions. Primary purpose: 1. compute logical values 2. used as conditional expressions in control-flowstatements like if-then, if-then-else, while-do statements. Relational expressions : A relop B where A & B are arithmetic expressions. Relop can be of the following types : < , > , <= , >= , == , != etc. .

Three Address Code Generation: • Ta-code for Jump can be of two types : a) if (X relop Y) goto L; Conditional Jump b) goto L; Unconditional Jump • Example 1. if (A<B and C<D) Three Address code: If (A < B) goto L 1 Goto L 3 L 1: If (C < D) goto L 2 Goto L 3 L 2: Code for correct condition L 3: Code for incorrect condition

More Examples • • Example 2. if (A<B or B<D) Three Address Code: If (A < B) goto L 2 Goto L 1: If (C < D) goto L 2 Goto L 3 L 2: Code for correct condition L 3: Code for incorrect condition • Example 3. a or b and not c Three Address Code: • t 1 = not c • t 2 = b and t 1 • t 3 = a or t 2

t=a<b Using Previous Method : • if a<b goto L 1; • goto L 2; • L 1: t = 1; • goto L 3; • L 2: t =0; • L 3: --------------------Replacing Labels by Address : • if a<b goto nextstat+3; • t =0; • goto nextstat+2; • t =1;
- Slides: 5