Drawing ASTs for expressions: Correct Solution


For each of the Java expressions below:

Be sure that your tree accurately reflects how Java would evaluate the expression.

Part 1

Given the following variables:

double pirget = 4.0;
double stomeounks = 4.0;
int pri = 8;
int cec = 1;
double in = 2.0;

...draw the AST and evaluation results for the following expression:

(pirget / 6 - 6 % 3 * 7 + stomeounks - 3 / pri + cec / in / 3 * 6)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double thui = 3.0;
double cim = 3.0;
double siath = 3.0;
int ehass = 5;
int o = 6;
int ent = 8;
double pilfar = 4.0;
boolean wobon = true;
double ounfia = 4.0;
double ro = 3.0;

...draw the AST and evaluation results for the following expression:

2 > thui == (!(7 != cim)) && siath < ehass != 7 <= o || ent > pilfar != !wobon != (7 == 3) == 3 < 9 == ounfia >= 1 != (!(0 == 1)) || 9 < ro

Solution

Things to double-check in your solution:


Part 3

Draw the AST and evaluation results for the following expression:

0 + 1 + 2 + 3 + "4" + 5 + "6" + 7 + 8 + 9 + "10" + 11 + 12

Solution

Things to double-check in your solution:


Related puzzles: