search
Log In
3 votes
596 views
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.
in Compiler Design
edited by
596 views
1

@Sambhrant Maurya, Can you please add the question source ?

2 Answers

5 votes
 
Best answer
(((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
0
Why are you repeating t1? Shouldn't the L.H.S be a unique variable?
5
Min No of register required=2

Min no of tem variable required=5
0
No ,  need not becoz here if we store even in t1 then also no problem as we dnt need t1 again later
0

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

but it doesnot rewrite inside same temp variable 

0
How to know when the temporary variables can be repeated on the LHS?
0

Ullman page 364

1 vote
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.
0
The answer is 2.
1
5 require if they mention SSA right

But here only mention 3 address code

So at left side variable can be repeat.

So only 2 variable are enough

Related questions

2 votes
0 answers
1
2 votes
1 answer
2
529 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?
asked Dec 10, 2015 in Compiler Design monanshi 529 views
1 vote
1 answer
3
212 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 comes different
asked Jan 8, 2019 in Compiler Design Markzuck 212 views
0 votes
2 answers
4
304 views
a x b x c + d - a + e x f - g + h order of precedence : x>+>- ; with x is left associative and +, - as right. Min number of variables required in TAC? Should'nt the expression be expressed as : ((a x b) x c) + d - a + (e x f) - g + h (((a x b) x c) + (d - (a + (e x f)) - (g + h)))
asked Nov 18, 2018 in Compiler Design manisha11 304 views
...