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 bensling = 3.0;
double eoli = 5.0;
int re = 7;
double stodsul = 3.0;
int amiorm = 4;
int hasshoism = 6;

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

8 - (4 % bensling - 8 % eoli - 6 * re * stodsul * amiorm) * hasshoism

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double egi = 4.0;
int ec = 2;
double cioudped = 2.0;
boolean wal = true;
int ti = 7;
int psaui = 3;
boolean ipshiss = false;
int snidtur = 4;
int riales = 4;

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

7 >= egi == (ec == cioudped) && 8 == 8 || (wal == ti < psaui || ipshiss && snidtur <= riales != 4 < 0 && 4 >= 9)

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

Solution

Things to double-check in your solution:


Related puzzles: