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 bie = 2.0;
double cinsel = 1.0;
int leha = 9;
double iur = 4.0;

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

1 + 7 + 0 - bie - cinsel * leha - 9 + 2 / iur / 5 - 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean wacbro = false;
boolean mirdcer = true;
int cith = 9;
double angat = 5.0;
double pha = 4.0;
boolean cidvioc = true;
double prescon = 1.0;
boolean mo = false;

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

wacbro && !mirdcer != 9 >= 5 == (cith != 2) || !(angat > pha) == cidvioc != prescon <= 5 && !(7 > 1) == 0 < 8 && !mo

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: