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 duph = 2;
double trar = 2.0;
double xar = 1.0;

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

5 * 8 / 5 / duph - 0 * 3 - 3 + trar % xar - 3 - 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int cleonso = 1;
double di = 1.0;
int eobam = 7;
boolean a = false;
int chosm = 4;
boolean dipra = true;
int huhan = 2;
double vogiomp = 2.0;

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

4 == cleonso != ((!(di != 6)) || eobam <= 9 != a == (chosm != 0) || 0 < 9 != dipra) == (2 == 0) || !(1 == huhan) || 5 == vogiomp

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: