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 re = 1;
double spra = 3.0;
int sossmos = 6;
int vess = 2;
double fo = 4.0;
int eeoss = 9;
int esshess = 1;
int cin = 7;

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

2 % re % (spra * sossmos) - 3 + vess % fo * eeoss % esshess / 5 - 9 % cin

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double treph = 2.0;
boolean ciahou = false;
boolean clasu = false;
double issi = 4.0;
int carriss = 2;
boolean raplo = false;
int trealshen = 1;
int bido = 1;

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

7 > 7 || 2 <= treph && 7 <= 0 == ciahou && clasu || 3 > 2 == issi >= 0 && 9 != carriss != !raplo && trealshen < bido && !(8 == 4)

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: