187k views
2 votes
Assume the following rules of associativity and precedence for expressions:

Precedence Highest *, /, not +, –, &, mod – (unary) =, /=, < , <=, >=, > and Lowest or, xor

Associativity Left to right

Show the order of evaluation of the following expressions by parenthesizing all subexpressions and placing a superscript on the right parenthesis to indicate order.

For example, for the expression a + b * c + d

the order of evaluation would be represented as ((a + (b * c)^1 )^2 + d)^3

Draw parse trees for the following expressions in exercise 9: a., d., and f.

a. a * b - 1 + c
d. -a or c = d
f. -a + b

User Tomet
by
4.1k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

the order of evaluation would be represented as

((a + (b * c)1)2 + d)3

a. a * b - 1 + c

b. a * (b - 1) / c mod d

c. (a - b) / c & (d * e / a - 3)

d. -a or c = d and e

e. a > b xor c or d <= 17

f. -a + b

A:

(a) ( ( ( a * b )1 – 1 )2 + c )3

(b) ( ( ( a * ( b – 1 )1 )2 / c )3 mod d )4

(c) ( ( ( a – b )1 / c )2 & ( ( ( d * e )3 / a )4 – 3 )5 )6

(d) ( ( ( – a )1 or ( c = d )2 )3 and e )4

(e) ( ( a > b )1 xor ( c or ( d <= 17 )2 )3 )4

(f) ( – ( a + b )1 )2

User Ron Ballard
by
3.5k points