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 thesmdork = 3.0;
double ir = 2.0;
int senchoc = 4;
int el = 2;
int espun = 1;

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

3 * thesmdork * ir + 5 - senchoc % 9 % 2 * el - espun

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ress = 9;
int ho = 5;
double stoil = 3.0;
int fa = 2;
boolean ecsan = false;
boolean sowir = true;
int apeax = 2;
double bluma = 3.0;

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

ress != ho && !(9 != stoil) == (7 == 7) != fa <= 7 == ecsan && sowir == apeax <= 0 && bluma <= 3

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

Solution

Things to double-check in your solution:


Related puzzles: