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 astrac = 2.0;
double iossce = 2.0;
double iasmdoc = 1.0;

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

6 * 9 / (6 / 1 * 9 * astrac) / iossce / iasmdoc * 7 % 2 * 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double strusthor = 1.0;
int er = 6;
int seddar = 4;
double ed = 1.0;
double ocsiss = 3.0;
double arnad = 2.0;
int osma = 6;
double ca = 2.0;
int puard = 9;
int rharco = 3;
int boono = 8;

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

strusthor >= 6 || 5 < 4 != 1 <= er || !(9 == seddar) && !(ed >= ocsiss) == 9 >= arnad != (osma != ca) != 5 < puard != rharco < boono && 2 <= 2

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: