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 erpse = 8;
double wa = 2.0;
int o = 6;
double roem = 3.0;

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

erpse - wa / 3 / o + 9 + roem

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double clen = 1.0;
boolean u = true;
double ic = 1.0;
int vu = 4;

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

clen == 1 || u || (3 <= ic != 6 >= 2) == (1 == vu)

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: