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 swif = 5.0;
int as = 3;
double jinct = 4.0;
int mu = 7;
int santsong = 8;

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

swif / 2 / 2 % as + jinct / mu / 4 % 1 % 7 % santsong

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int zindmid = 6;
int phur = 1;
double si = 4.0;
double brerca = 2.0;
int seet = 7;
double ceaek = 1.0;
double irdant = 4.0;
double od = 2.0;
int tia = 5;
int hess = 9;
boolean schie = true;
boolean isbah = false;

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

zindmid >= phur && !(4 >= si) || 0 < brerca && seet < ceaek == irdant >= od || 3 <= 8 && tia > hess == schie && isbah

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)

Solution

Things to double-check in your solution:


Related puzzles: