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 ost = 3;
double esseb = 2.0;
double hifthat = 4.0;
int e = 6;
int ac = 2;
double a = 4.0;
double i = 1.0;
double drongfur = 3.0;

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

3 + ost - esseb / hifthat + e - ac / a + i / drongfur

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean trissdeoust = false;
double dacca = 3.0;
boolean issde = true;
double rini = 3.0;
int tantew = 5;

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

trissdeoust || 2 > 5 == 5 > dacca || 8 == 7 == issde == 3 > rini && 0 > 1 != (1 == tantew)

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: