Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i)Write three-address code for the following expressions: a)x = a + b * c- d / (b*c). b)x = (a*b)+(c+d) - (a+b+c+d) ii)Consider the following

i)Write three-address code for the following expressions:

a)x =a + b * c- d / (b*c).

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

ii)Consider the following expressions and construct DAGs for it:

a)(((a-a)+(a-a)+((a*a)+(a*a)))

b)(a*b)*(b*e)+(a*b)*(b*e)

sol33:

i) Three-address code for the following expressions:

a) x = a + b * c - d / (b*c)

t1 = b * c

t2 = d / t1

t3 = a + t2

t4 = t3 - t1

x = t4

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

t1 = a * b

t2 = -t1

t3 = c + d

t4 = a + b

t5 = t4 + c

t6 = t5 + d

t7 = t2 + t3

x = t7 - t6

ii) DAGs for the following expressions:

a) (((a-a)+(a-a)+((aa)+(aa))))

+ +

/ \\ / \\

- - * *

/ \\ / \\ / \\ / \\

a a a a a a

b)(ab)(be)+(ab)(be)

* *

/ \\ / \\

* * * *

/ \\ / \\ / \\ / \\

a b b a b b

| |

* *

/ \\ / \\

b e b e

Explanation:

In the first expression, we can see that some sub-expressions like (a-a) and (a*a) are being repeated multiple times. Using a DAG, we can represent these sub-expressions only once and reuse them wherever required, which reduces the number of computations and improves efficiency.

In the second expression, we can see that the expressions (a*b) and (b*e) are being multiplied twice. Using a DAG, we can represent these sub-expressions only once and reuse them wherever required, which reduces the number of computations and improves efficiency.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Design Operation And Evaluation Of Mobile Communications

Authors: Gavriel Salvendy ,June Wei

1st Edition

3030770249, 978-3030770242

More Books

Students also viewed these Programming questions

Question

Distinguish between a priori and a posteriori knowledge.

Answered: 1 week ago