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 ec = 8;
double treell = 4.0;
double se = 3.0;
int obiss = 4;
double acdo = 5.0;

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

ec - treell / 4 / (4 % se - 1 - obiss - 2 % 4) % 5 % acdo

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double o = 2.0;
int me = 9;
boolean co = true;
int diu = 5;
int codeng = 1;
int cilnal = 4;
int ma = 7;
double gahios = 2.0;
double hercid = 4.0;

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

o == 9 && 1 > me != !co || (!(1 > 4) == (1 != diu) && codeng >= cilnal || ma < gahios) || 0 < 7 != hercid > 9 || !(0 < 5)

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: