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 di = 3.0;
int toainch = 4;
double u = 2.0;

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

2 - di + 8 % toainch / 4 + 6 % 6 + u - (0 - 5)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int oe = 7;
double vec = 2.0;
int is = 9;
double ra = 5.0;
boolean sulktics = true;
boolean banmea = false;
boolean ciol = false;
boolean usphox = true;
int rol = 4;
double esm = 1.0;
boolean ste = false;

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

oe > vec || is != ra != (6 == 1) || sulktics != banmea || ciol || usphox == !(!(rol < esm)) != ste

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: