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 fepraw = 3.0;
double ei = 3.0;
int ortra = 5;

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

fepraw - 1 * 7 - ei - ortra - 9 + 7 / 4 - 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double so = 1.0;
boolean iu = false;
double lo = 3.0;
boolean chath = false;
double entiff = 4.0;
int igren = 3;
double ia = 5.0;
int ci = 9;
int sanwest = 4;
double ul = 4.0;

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

!(!(so == 1)) != (9 != 9) == (iu == (lo == 0) != chath != (entiff == igren) || ia >= ci) || !(sanwest >= ul)

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: