2. Intermediate Code Generations
An intermediate representation of the final machine language
code is produced. This phase bridges the analysis and synthesis
phases of translation.
Example
temp1:= int to real (60)
temp2:= id3 * temp1
temp3:= id2 + temp2
id1:= temp3.
id1 = id2 + id3 * id4
6. • Grammar + Semantic Rules= SDD
• SDD for Evaluation of Expression
E E+T {E.value=E.value+T.value}
E T {E.value=T.value}
T T*F {T.value=T.value*F.value}
T F {T.value=F.value}
F num {F.value=num.value}
Syntax Directed Definition (SDD)
Example1
8. • Example2
Syntax Directed Definition (SDD) Cont..
L E {L.val=E.val}
E E1+ T {E.val= E1.val+ T.val}
E T {E.val=T.val}
T T1*F {T.val= T1.val*F.val}
TF {T.val=F.val}
F(E) {F.val=E.val}
F digit {F.val=digit.lexval}
13. SDD Attribute Types
• Inherited Attribute value defined by its
parent or siblings or itself
S- Attributed Definitions: synthesized
L- Attributed Definitions: Synthesized and
Inherited
14. • E E*T {E.val=E.val*T.val}
• E T {E.val=T.val}
• T F-T {T.val=F.val – T.val}
• T F {T.val=F.val}
• F 2 {F.val=2}
• F 4 {F.val=4}
Syntax Directed Definition (SDD) Cont..
• Example4
33. • Assignment Statement : x:=y op z
– op Arithmetic or logical operator
• Assignment Statement : x:= op y
– op Unary Operator
• Copy Statement : x:=y
• Unconditional Jump : goto L
• Conditional Jump : if x relop y goto L
• Procedure call : p(x1,x2,x3,…,xn)
Param x1
Param x2
…………..
Param xn
Call p,n
Type of 3- Address Statements
34. • In compiler the 3 address code is field of records
Quadruples
Triples
Indirect Triples
3- Address Code