retagged by
2,286 views
4 votes
4 votes
The minimum number of temporary variables created in 3 address code of the following expression are _____
                   a+b*c+d-e-a+b*c

Assume order of precedence from highest to lowest as: *,+ and - .Consider associativity for + and * are not important but - is left associative.
retagged by

2 Answers

Best answer
7 votes
7 votes
(((a+(b*c))+d)-e)-(a+(b*c))    [ as * have highest precedence so should be done first , then + should be dne ad then -                                                                             and as associativity of + is not importnat so i m taking + as left associative]

t1 = b * c;

t2 = a + t1;

t1 = t2 + d;

t1 = t1 - e;

t1 = t1 - t2;             so minimum 2 temporary variables are needed {t1 , t2 }
selected by
1 votes
1 votes
Question mentioned the statement  : a+b*c+d-e-a+b*c

"Temp variables created by the compiler as needed to keep the number of operands down"

Three Address Code represented as below :

Precedence is * is highest, so it is evaluated first.

t1 = b * c

t2 = a + t1

t3 = t2 + d

t4 = t3 - e

t5 = t4 -t2

So minimum 5 temp variables needed.

Related questions

2 votes
2 votes
1 answer
1
dragonball asked Jan 14, 2018
1,476 views
2 votes
2 votes
1 answer
2
monanshi asked Dec 10, 2015
1,857 views
During code generation, we need to do register allocation (kind of machine dependent stuff). So, I think it must be the part of Synthesis phase?
1 votes
1 votes
1 answer
3
Markzuck asked Jan 8, 2019
743 views
someone please share detailed rules for this along with solution- would be of great help.and we usually dont take start and end state- arent they extra here? coz count co...