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 o = 7;
int udmong = 2;
double ble = 5.0;
double teoc = 5.0;
double oerl = 1.0;
int e = 1;
double ozar = 5.0;
double lanpee = 2.0;
double irdden = 2.0;

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

o + udmong + ble - teoc + oerl - e + 5 * ozar / lanpee - 6 / 2 % irdden

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean spewpru = true;
boolean casvaent = true;
double erdos = 3.0;
int prassdir = 7;
int er = 5;
int vinchuss = 6;
int rono = 7;
boolean tholas = true;
int onchi = 7;
int asphaeck = 3;
boolean teup = true;
boolean swe = false;

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

spewpru == casvaent || erdos != prassdir && er >= 8 || vinchuss != 5 != 7 >= rono || 0 <= 1 == tholas != onchi <= asphaeck || teup == swe

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" + 12

Solution

Things to double-check in your solution:


Related puzzles: