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 cisdo = 6;
double anen = 5.0;
double ra = 4.0;
int ipec = 4;

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

5 % cisdo % anen / (5 + ra * ipec) + 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean thith = true;
double litchlind = 2.0;
int ensid = 3;
double ced = 2.0;
int rul = 5;

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

!thith == litchlind > 5 && ensid < ced && rul == 6 == 4 < 5 != (!(1 != 8))

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)

Solution

Things to double-check in your solution:


Related puzzles: