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 ce = 2.0;
int ri = 6;
int ptisssor = 5;
double mo = 2.0;
double ichtess = 3.0;
double enthim = 5.0;

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

ce / ri % ptisssor / mo + 8 / 7 / 8 / ichtess + 8 - enthim - 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double giau = 1.0;
boolean vocem = false;
boolean eabun = true;
int i = 3;
int pimec = 5;
int engtre = 1;
int co = 6;

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

7 == 7 && giau == 7 != 1 <= 8 == vocem == !(6 > 1) != eabun == 0 <= i != !(!(pimec >= engtre)) == 6 >= co || 0 > 2

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: