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 draknoc = 1.0;
double ic = 2.0;
int thuo = 5;
int cibasm = 1;
double zaho = 2.0;
double ledial = 2.0;
int tith = 2;

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

draknoc + ic * thuo + 2 / (4 * cibasm % zaho % ledial * 4 * 5 - tith)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int e = 2;
double tasent = 5.0;
int be = 9;
int u = 2;
double hiax = 4.0;
int eg = 9;
boolean caess = false;
boolean saidnosm = true;
boolean ed = false;

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

e >= tasent != 4 > 9 || be == u == hiax < eg && 5 >= 1 && caess && saidnosm == 8 < 5 == ed && 8 > 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" + "10" + "11"

Solution

Things to double-check in your solution:


Related puzzles: