CD Unit-4 (Part-2)
CD Unit-4 (Part-2)
Unit – 4 (Part – 2)
Intermediate Code
Generation
+
a +
a
* * *
Ex: (A + B) * C
Postfix notation: A B +
C*
Postfix notation: A B *
Ex: (A * B) + (C * D)
CD*+
CD Unit 4 (Part – 2) – Intermediate Code
Mr.
Prof.
Viral
JayH.RPanchal
Dhamsaniya #3130006 (PS) Unit 1 – Basic Probability 6
Three address code
Three address code is a sequence of statements of the general form,
a:= b op c
Where a, b or c are the operands that can be names or constants and op
stands for any operator.
Example: a = b + c + d
t1=b+c
t2=t1+d
a= t2
Here t1 and t2 are the temporary names generated by the compiler.
There are at most three addresses allowed (two for operands and one for
result). Hence, this representation is called three-address code.
Quadruple Triple
No Operat Arg1 Arg Result No Operat Arg Arg
.(0) or 2 .(0) or
uminus 1
a 2
uminus a t1
(1) * t1 b t2 (1) * (0) b
(2) uminus a t3 (2) uminus a
(3) * t3 b t4 (3) * (2) b
(4) + t2 t4 t5 (4) + (1) (3)
(5) = t5 x (5) = x (4)