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 a = 7;
double ro = 3.0;
double ge = 1.0;
double plepmec = 3.0;
int fiet = 9;

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

5 - a + ro - 6 / ge + plepmec - 9 - 0 * (8 % 6 + fiet) - 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double essner = 3.0;
double mitroosm = 1.0;
int sa = 1;
double prace = 5.0;
boolean zoc = true;
boolean om = false;
int mo = 9;
double banmad = 4.0;
int mealtrith = 7;
int rida = 9;
double anun = 1.0;

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

essner >= mitroosm || sa == 1 != ((prace != 7) || zoc == !om) != !(6 >= mo) || 8 < banmad == mealtrith < 7 || 2 >= 8 == rida >= anun != (!(8 == 0))

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: