The Gateway to Computer Science Excellence
0 votes
121 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 Active (2.6k points)
edited by | 121 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 Active (2.9k points)
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
50,647 questions
56,492 answers
195,439 comments
100,711 users