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 iiwhe = 4.0;
double wirthcoc = 4.0;
double eghtsu = 2.0;
double smoessjil = 2.0;
int id = 9;

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

iiwhe - wirthcoc / eghtsu / 5 / 5 * smoessjil + 4 / 8 * (2 % id * 6 - 4)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int eheud = 9;
boolean fiandro = true;
double di = 2.0;
double miobnont = 3.0;
int stollqo = 5;
boolean binras = false;
boolean a = false;

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

(3 >= 5 != (5 != 1) == 0 >= eheud || 3 > 9) && fiandro || 7 > 2 && di > 9 && miobnont == stollqo == binras && a != (7 == 1)

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: