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 he = 1.0;
double osscuin = 3.0;
int il = 2;

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

0 % he % 4 + 5 + osscuin + il / 8 % 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean rac = false;
double ratwusm = 4.0;
double zabip = 4.0;
double miosspriod = 1.0;
int udeog = 6;
double pori = 2.0;
int ches = 8;
int passwuss = 1;
boolean acund = false;

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

rac != (!(ratwusm < zabip) || miosspriod == udeog != (pori == ches)) == (6 == passwuss) || !(2 > 5) != acund

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: