Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compiler Construction

Similar presentations


Presentation on theme: "Compiler Construction"— Presentation transcript:

1 Compiler Construction
Chapter 8 Compiler Construction Dr K. V. N. Sunitha

2 Intermediate Code Generation
Compiler Construction Dr K. V. N. Sunitha

3 Intermediate Languages
There are three types of intermediate representation: Syntax trees Postfix notation Three address code DAG Compiler Construction Dr K. V. N. Sunitha

4 Compiler Construction
Syntax Tree a = b* − (c − d) + b* − (c − d) Compiler Construction Dr K. V. N. Sunitha

5 Compiler Construction
Postfix Notation a = b* − (c − d) + b* − (c − d) Postfix form is as follows: a b c d – - * b c d – - * + = Compiler Construction Dr K. V. N. Sunitha

6 Compiler Construction
Three-Address Code Three address code for the statement a= b* − (c − d)+b* − c − d) is T1 = c − d T2 = − T1 T3 = b*T2 T4 = c − d T5 = − T4 T6 = b*T5 T7 = T3+T6 a = T7 Compiler Construction Dr K. V. N. Sunitha

7 Compiler Construction
DAG a = b* − (c − d) + b* − (c − d) is = + * b - - c d Compiler Construction Dr K. V. N. Sunitha

8 Implementing Three-Address Code
Quadruple • a record structure with four fields Triple • a record structure with three fields Indirect triples • pointer to triples Compiler Construction Dr K. V. N. Sunitha

9 Types of Three-Address Statements
A := B op C A := op B A :=B goto L. if A relop B goto L A: = B[ i ] A:= &B A:= *B B fun(A1,A2,A3,....An) Compiler Construction Dr K. V. N. Sunitha

10 Three-Address Statement for the x or y not z
t1 = not z t2 = y and t1 t3 = x or t2 Compiler Construction Dr K. V. N. Sunitha

11 Compiler Construction
If x < y Then 1 Else 0 Three address code is if a < y go to 13 t1 = 0 go to 14 t1 = 1 Compiler Construction Dr K. V. N. Sunitha

12 IR Translation of Conditional Statement
S → if E then S1 {E.true = newlabel(); E.false = S.next; S1.next = S.next; S.code = E.code || gen(E.true , “ :”) || S1.code } Compiler Construction Dr K. V. N. Sunitha

13 IR Translation of While Loop
S → while E do S1 {S.begin = newlabel(); E.true = newlabel(); E.false = S.next; S1.next = S.next; S.code = gen(S.begin “:”) || || E.code || gen(E.true , “ :”) || S1.code || gen(“GOTO” , S.begin) } Compiler Construction Dr K. V. N. Sunitha


Download ppt "Compiler Construction"

Similar presentations


Ads by Google