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 vung = 3.0;
int banschic = 1;
double traciss = 1.0;
int piri = 7;
double lardpar = 2.0;
double ontra = 5.0;

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

vung + banschic % traciss * piri + (lardpar * ontra)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double bix = 4.0;
int dockna = 3;
int espim = 9;
int ce = 2;
double brar = 4.0;
double proass = 5.0;

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

bix == dockna || espim > 9 != ce <= 0 || (brar > proass || !(1 == 9))

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)

Solution

Things to double-check in your solution:


Related puzzles: