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 landu = 4.0;
int stred = 5;
int mioss = 3;
int fioccu = 1;
int pierm = 2;
double du = 5.0;
double roumbror = 5.0;
int zedtoc = 1;

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

(landu / stred / mioss / fioccu / 6 + 1 - pierm + du - roumbror) - 8 - zedtoc

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double e = 1.0;
int meesmred = 4;
boolean ad = false;
double ed = 3.0;
int bil = 4;
int zano = 6;
int idoi = 8;
boolean vocu = true;
int ounar = 1;
double milont = 4.0;
int nesshost = 4;

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

9 >= 8 == (!(e != meesmred)) != ad || ed <= 4 == (bil == 6) != (zano > idoi == vocu) && ounar < 4 || 7 < milont != 4 > nesshost

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: