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 okrer = 4;
int cioue = 5;
double e = 5.0;
double pothdorm = 5.0;

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

okrer + 4 % 1 % cioue + e - 0 * pothdorm / 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean di = true;
double cidec = 3.0;
boolean fenhu = false;
int ri = 4;
int grimu = 4;
boolean treft = true;

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

di != 0 >= 8 || 8 != cidec != fenhu || ri <= grimu || treft != 9 < 1

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

Solution

Things to double-check in your solution:


Related puzzles: