Three Address Statement Types - Compiler Construction - Lecture Slides, Slides of Compiler Construction

Three Address Statement Types, Assignment statement, Arithmetic operation, Logical operation, Unary minus, Copy statement, Unconditional jump are basic concepts discussed of course.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekavia
ekavia 🇮🇳

4.3

(58)

241 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Compiler
Construction
Lecture 38
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Three Address Statement Types - Compiler Construction - Lecture Slides and more Slides Compiler Construction in PDF only on Docsity!

Compiler

Construction

Lecture 38

2

Three-Address Statement Types

 Prior to proceeding with flow- of-control construct, here are the types of three-Address statements that we will use

4

Three-Address Statement Types

Assignment statement

x = op y

where op is a unary operation, e.g., unary minus, logical negation, shift operators

5

Three-Address Statement Types

Copy statement

x = y

where value of y is assigned to x

7

Three-Address Statement Types

Conditional jump

if x relop y goto L

where relop is <, =, >=, etc. If x stands in relation relop to y , execute statement with label L , next otherwise

8

Three-Address Statement Types

Indexed assignment

a) x = y[i] b) x[i] = y In a), set x to value in location i memory units beyond location y.

10

Array of Quadruples

Label Target Op Arg1 Arg L1 if_lt c d L2 goto L1: x (^) + y z L3 goto L2: x – y z L3: nop

11

Flow-of-Control Statements

 We associate with a boolean expression E two labels; E.true and E.false

 The control flows to E.true if the expression evaluates to true, to E.false otherwise

13

to E.true to E.false E.true:

E.false:

E.code

S 1 .code .......

S → if E then S 1

14

Syntax-directed translation for S → if E then S (^1)

E.true = newlabel() E.false = S.next S 1 .next = S.next S.code = E.code || gen(E.true ‘:’) || S 1 .code

inherited attribute

16

Flow-of-Control Statements

 Suppose E is a < b. E.code is

if a < b goto E.true goto E.false

 We will discuss semantic rules for boolean expressions shortly

17

S → if E then S 1 else S 2

to E.true to E.false E.true:

E.false:

E.code S 1 .code

.......

goto S.next S 2 .code S.next:

19

while E do S 1

to E.true to E.false E.true:

E.false:

E.code S 1 .code

.......

goto S.begin

S.begin:

20

S → while E do S (^1)

S.begin = newlabel() E.true = newlabel() E.false = S.next S 1 .next = S.begin S.code = gen(S.begin ‘:’) || E.code || gen(E.true ‘:’) || S 1 .code || gen(‘goto’ S.begin)