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 ticrash = 5.0;
int edior = 6;
double qojem = 2.0;
double leoben = 3.0;
int derra = 6;
int jirbist = 8;
int heso = 3;

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

ticrash * edior * 6 % qojem - 8 + 4 - 7 / leoben % derra * (jirbist - 5 * heso)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean sonen = true;
double chist = 1.0;
double fle = 3.0;
int mosfen = 9;
int riassa = 4;
boolean ec = false;
double phal = 5.0;
double mo = 3.0;

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

(sonen != 3 >= 0 != !(!(6 < 1)) && chist <= fle && mosfen <= 5 != riassa <= 0) == (5 != 6) == ec != 6 >= phal != 4 >= 5 && mo == 3

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 + 12

Solution

Things to double-check in your solution:


Related puzzles: