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 bretresh = 7;
double apkin = 3.0;
int tia = 8;
double miamsi = 5.0;
double spul = 3.0;
int a = 1;
double o = 3.0;

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

bretresh / 5 / 6 % apkin + tia % miamsi % spul % 1 * 4 + a % 8 % o

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double hetios = 3.0;
double cluss = 5.0;
boolean paftis = false;
int stil = 9;
int le = 2;
double etam = 1.0;
int ce = 9;
boolean preschu = false;
boolean ocmu = true;
double eoustdear = 2.0;
boolean at = true;
double cripfle = 3.0;

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

5 < hetios == 4 < cluss == paftis == !(stil < le) && etam >= ce && preschu == ocmu && !(1 == eoustdear) == 1 <= 9 != at && cripfle == 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" + 12

Solution

Things to double-check in your solution:


Related puzzles: