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 ca = 2;
int sphuil = 6;
int spicment = 9;
double cu = 2.0;
int su = 3;
double somess = 4.0;
double plel = 1.0;
int psalsoul = 2;

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

ca - sphuil - spicment * cu * 8 / su * somess - plel + psalsoul

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean hiroe = false;
int e = 9;
int meshca = 8;
double monra = 2.0;
int disle = 2;
int missuis = 7;
double meddo = 1.0;
double gea = 4.0;
double phua = 5.0;
double treloun = 5.0;

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

hiroe != e < meshca || monra >= 4 != 2 <= 4 || disle <= missuis != 9 >= meddo && 5 == gea && phua <= treloun

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"

Solution

Things to double-check in your solution:


Related puzzles: