Professional Documents
Culture Documents
1:
Write Three Address Code for the following expressions.
I. -(a x b) + (c + d) – (a + b + c + d)
Solution:
Three Address Code for the given expression is-
(1) T1 = a x b
(2) T2 = uminus T1
(3) T3 = c + d
(4) T4 = T2 + T3
(5) T5 = a + b
(6) T6 = T3 + T5
(7) T7 = T4 – T6
II. a+a*(b-c)+(b-c)*d
Solution:
t1 = b - c
t2 = a * t1
t3 = a + t2
t4 = t1 * d
t5 = t3 + t4
Q no.2:
Write quadruple, triples and indirect triples for following expression.
(x + y) * (y + z) + (x + y + z)
Solution:
t1 = x + y
t2 = y + z
t3 = t1 * t2
t4 = t1 + z
t5 = t3 + t4
Quadruple Representation:
# OP ARG 1 ARG 2 RESULT
1 + X Y T1
2 + Y Z T2
3 * T1 T2 T3
4 + T3 Z T4
5 + T3 T4 T5
Triple Representation:
# OP ARG 1 ARG 2
1 + x y
2 + y z
3 * 1 2
4 + 1 z
5 + 3 4
B + Y Z
C * A B
D + A Z
E + C D
List of pointers:
# STATMENT
1 A
2 B
3 C
4 D
5 E