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 ni = 9;
double na = 4.0;
int ke = 1;
double inu = 1.0;
double vuw = 1.0;
double farua = 5.0;
int besas = 1;

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

2 * 4 - ni / 8 % na + ke % inu % vuw - farua / 5 * besas

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int phelos = 1;
int ursot = 9;
int vor = 4;
double ronho = 4.0;
double suntown = 2.0;
int cirdcol = 2;
int co = 1;
boolean iec = false;
boolean ve = true;

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

6 > phelos || 2 < 8 && (9 >= 3 || 7 != ursot && vor > 2 || 6 >= ronho && 6 >= suntown == cirdcol <= co) && iec || ve

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: