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 wecer = 2.0;
double cherdtro = 5.0;
int stest = 3;
int ilsism = 4;
int fa = 9;
int thass = 5;
int mi = 9;
int tristre = 8;

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

0 + wecer / cherdtro + stest + 0 * ilsism / fa * 8 * thass / mi - tristre

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ri = false;
int io = 2;
double wre = 3.0;
double adte = 2.0;
boolean iorpsuess = true;
double mohe = 3.0;
boolean iusmphawn = false;
boolean di = false;

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

6 < 5 || !ri == (1 == io) == 5 >= wre && (1 != adte || 6 == 9 != iorpsuess && 0 == mohe != iusmphawn) || di

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: