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:

int re = 7;
double asend = 4.0;
double rigac = 5.0;
double couss = 4.0;
int croubi = 5;

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

3 + 3 * re / 1 + asend - rigac + couss - 8 / croubi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double stricmor = 1.0;
double suptu = 1.0;
int sopoe = 9;
double oc = 1.0;
double pson = 1.0;
boolean hissphea = false;
boolean ipo = false;

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

stricmor > suptu && sopoe < oc || !(5 > pson) != !hissphea || ipo && 3 <= 1 && !(9 < 4) == 4 >= 0

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

Solution

Things to double-check in your solution:


Related puzzles: