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 ad = 2.0;
double haa = 5.0;
double si = 3.0;
int plisdict = 1;

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

8 * ad / 1 - haa % 3 / 6 * si + (plisdict * 6) + 5 / 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double feor = 3.0;
double brooc = 4.0;
double casscror = 5.0;
int in = 4;
int thaa = 4;
double snad = 3.0;
double esnis = 1.0;
double umir = 1.0;
boolean cempi = true;
double bleacin = 1.0;

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

5 < 0 == (feor == 0) || brooc > 3 && !(3 != casscror) || 6 == in == !(!(thaa > 7)) || snad == esnis && !(umir <= 9) == cempi || 2 <= bleacin

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: