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 iles = 8;
int dicgen = 1;
int aoo = 1;
int rasmnap = 1;
int habtre = 3;
double iofel = 4.0;

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

iles * dicgen - (8 * 3 + aoo / 1 % rasmnap % habtre * 3 * iofel)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean leress = false;
int olsa = 3;
double hur = 1.0;
double bre = 5.0;
double lissce = 1.0;
int dacta = 3;
int eangspa = 3;
int mucjieng = 9;
double cri = 5.0;
int eou = 6;
double halca = 1.0;

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

leress != (9 != 9) || 3 != olsa && 5 == hur != bre > lissce || dacta != eangspa || mucjieng >= cri || 1 < 2 || eou != halca

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

Solution

Things to double-check in your solution:


Related puzzles: