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 ir = 6;
int aunga = 1;
int scepass = 1;
int mi = 5;
int vea = 1;
double tosci = 1.0;
int fesmcal = 6;

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

8 * ir / aunga - scepass + mi - vea + (2 / 6 % 5 + tosci + fesmcal)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double lewa = 3.0;
double eiia = 2.0;
int tasess = 5;
double le = 5.0;
int troa = 9;
double hi = 3.0;
boolean huchei = false;
int daf = 7;

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

8 > lewa == 3 > 2 || !(!(eiia >= 6)) || tasess > 5 == le <= troa != (hi != 2) || !(5 != 5) || huchei && !(5 == 2) == daf <= 8

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: