The Gateway to Computer Science Excellence
0 votes
130 views
Consider the following expression:

(a+a*(b-c)+(b-c)*d)

What is the minimum number of three address statements for the expression?

My question is whether we should optimize the expression before evaluating it or go as it is. For instance the above expression can be optimized as (a+(b-c)*(a+d)) which would generate lesser number of statements.
in Compiler Design by
edited by | 130 views

1 Answer

0 votes
Best answer

5 statements would be needed.

t1=b-c;

t2=a*t1;

t3=d*t1;

t4=t2+t3;

t5=a+t4;

Never try to optimise the expression unless they say algebraic simplifications or code optimisations are allowed or place a restriction on number of temorary variables.

by
selected by

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,315 questions
60,428 answers
201,759 comments
95,238 users