# Ullman (Compiler Design) Edition 2 Exercise 6.2 Question 2 (Page No. 370)

1 vote
369 views

Translate the  following arithmetic expression into:

1. $a=b[i]+c[j]$
2. $a[i]=b\ast c-b\ast d$
3. $x=f(y+1)+2$
4. $x=\ast p + \&y$

1. A Syntax tree
3. Triples
4. Indirect triples

1. a=b[i]+c[j]

 Operator Argument1 Argument2 Result 0 =[] b i t1 1 =[] c j t2 2 + t1 t2 t3 3 = t3 a

Triples

 Operator Argument1 Argument2 0 =[] b i 1 =[] c j 2 + (0) (1) 3 = a (2)

Indirect Triples

 0 (0) 1 (1) 2 (2) 3 (3)

2. a[i]=b∗c−b∗d

 Operator Argument1 Argument2 Result 0 * b c t1 1 * b d t2 2 - t1 t2 t3 3 []= a i t4 4 = t3 t4

Triples

 Operator Argument1 Argument2 0 * b c 1 * b d 2 - (0) (1) 3 []= a i 4 = (3) (2)

edited by
0

Is it right for equation 3 & 4?

0
i'm not sure of representing function calls in DAG
0

@Lakshman Patel RJIT

0

## Related questions

1
186 views
Show how to transform a three-address code sequence into one in which each defined variable gets a unique variable name.
Translate the arithmetic expression $a + -(b + c)$ into: A syntax tree. Quadruples. Triples. Indirect triples
As in Ada, suppose that each expression must have a unique type, but that from a subexpression, by itself, all we can deduce is a set of possible types. That is, the application of function $E_{1}$ to argument $E_{2}$ ... and, once the unique type of the overall expression is determined, proceeds top-down to determine attribute $unique$ for the type of each subexpression.
Assuming that function $widen$ in Fig. $6.26$ can handle any of the types in the hierarchy of Fig. $6.25(a)$, translate the expressions below. Assume that c and d are characters, $s$ and $t$ are short integers, $i$ and $j$ are integers, and $x$ is a float. $x=s+c$ $i=s+c$ $x=(s+c)\ast(t+d)$