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 sanbroi = 3;
double hiochi = 5.0;
int reanthas = 1;
double pheur = 2.0;
double muo = 5.0;
int gucfia = 6;
int ad = 5;
double binros = 2.0;

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

5 * sanbroi - hiochi - 9 * reanthas / pheur / muo % gucfia - (ad - binros)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ci = true;
boolean ud = true;
double phaco = 4.0;
int cou = 2;
boolean chewe = false;
boolean e = true;
double gedstoo = 1.0;

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

ci != (!(5 > 5) == ud) && phaco <= cou == chewe && 5 < 3 != (6 == 8) || e != (8 != gedstoo)

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: