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 bial = 2.0;
double on = 5.0;
double i = 2.0;
double amhip = 2.0;

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

bial - 2 % 2 % 4 * 1 + 7 - on / 9 - i / 9 + amhip

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean dransce = true;
int e = 5;
double splan = 4.0;
int enu = 1;
int soonol = 4;
boolean ses = false;
int sinan = 6;

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

0 < 3 != dransce == 0 <= 0 || e > 3 || !(2 <= 6) || !(splan > enu) == 2 > 8 && 9 != soonol && !ses && sinan < 6

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 + 10 + "11"

Solution

Things to double-check in your solution:


Related puzzles: