








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Intermediate Code Generation, Translating source program, CPU Independent, Benefits, Retargeting is facilitated, Example of 3-address code.
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!









(^) Graphical Representations. (^) Consider the assignment a:=b-c+b-c:
(^) Statements of general form x:=y op z (^) As a result, x:=y + z * w should be represented as t 1 :=z * w t 2 :=y + t 1 x:=t 2 (^) Observe that given the syntax-tree or the dag of the graphical representation we can easily derive a three address code for assignments as above. (^) In fact three-address code is a linearization of the tree. (^) Three-address code is useful: related to machine-language/ simple/ optimizable.
Assignment Statement: x:=y op z Assignment Statement: x:=op z Copy Statement: x:=z Unconditional Jump: goto L Conditional Jump: if x relop y goto L Stack Operations:Push/pop
Procedure: param x 1 param x 2 … param xn call p,n Index Assignments: x:=y[i] x[i]:=y Address and Pointer Assignments: x:=&y x:=*y *x:=y
Syntax-Directed Translation into 3-address code. (^) First deal with assignments. (^) Use attributes (^) E. place: the name that will hold the value of E (^) Identifier will be assumed to already have the place attribute defined. (^) E. code: hold the three address code statements that evaluate E (this is the `translation’ attribute).
can use.
necessary information (variable names and operations).
Extension to the previous syntax-dir. Def. PRODUCTION S while E do S 1 Semantic Rule S.begin = newlabel ; S.after = newlabel ; S. code = gen (S. begin ‘:’) || E. code || gen (‘if’ E. place ‘=’ ‘0’ ‘goto’ S. after ) || S 1. code || gen(‘goto’ S. begin ) || gen(S. after ‘:’)
(^) Quadruples t 1 :=- c t 2 :=b * t 1 t 3 :=- c t 4 :=b * t 3 t 5 :=t 2 + t 4 a:=t 5 op arg1 arg2 result (0) uminus c t 1 (1) * b t 1 t 2 (2) uminus c (3) * b t 3 t 4 (4) + t 2 t 4 t 5 (5) := t 5 a Temporary names must be entered into the symbol table as they are created.
(^) e.g. ternary operations like x[i]:=y x:=y[i] (^) require two or more entries. e.g. op arg1 arg (0) [ ] = x i (1) assign (0) y op arg1 arg (0) [ ] = y i (1) assign x (0)
op arg1 arg (14) uminus c (15) * b (14) (16) uminus c (17) * b (16) (18) + (15) (17) (19) assign a (18) op (0) (14) (1) (15) (2) (16) (3) (17) (4) (18) (5) (19)