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 kimvert = 3;
int thecir = 5;
double oss = 5.0;
double prown = 3.0;
int pecod = 9;
double shoshir = 4.0;
double siongste = 4.0;

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

kimvert - thecir - oss - prown % pecod * shoshir % siongste % 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int oassmos = 4;
double puwsif = 4.0;
int thoc = 8;
int ilbrea = 1;
int fa = 1;
double so = 1.0;
int gecess = 9;
int sphe = 4;
double broed = 5.0;
double romres = 2.0;

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

oassmos == puwsif != thoc >= 1 == (ilbrea != fa) == (!(0 == so)) == gecess >= sphe && 1 > 8 == broed > romres

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

Solution

Things to double-check in your solution:


Related puzzles: