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 ha = 3;
int renlo = 1;
int opest = 4;
double o = 1.0;
double pi = 3.0;
int sa = 1;
int u = 7;

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

3 % 6 + 6 - ha - renlo / 9 / opest / o % pi % sa / u

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean orwo = false;
boolean pid = false;
boolean vaera = true;
int ciehe = 2;
boolean plec = false;
double agior = 5.0;
double ia = 2.0;
boolean ze = true;
boolean teass = false;

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

(orwo || pid && vaera == 3 >= ciehe != plec || agior == 6 != ia >= 7 != (!(6 == 0)) != !ze) || !teass

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 + "10" + 11)

Solution

Things to double-check in your solution:


Related puzzles: