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 nint = 8;
int dursos = 6;
double vuantphled = 2.0;
double shucip = 2.0;

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

1 - 6 * 2 / nint - (dursos - 7 + vuantphled - 0 % shucip)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean or = true;
int bampro = 5;
double stiathen = 3.0;
int rer = 9;
boolean ceosde = false;
boolean prucreng = true;
boolean eec = true;
double oseg = 4.0;

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

or || bampro > stiathen == (rer == 8) && !ceosde == (prucreng == 9 <= 5 != !eec && oseg != 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: