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 madlen = 9;
int pa = 1;
int liat = 9;
double whe = 2.0;
int whil = 9;

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

madlen - 1 - 6 % 4 * 3 * pa * liat % whe * 7 - 3 - whil

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int mesirm = 1;
double me = 5.0;
int e = 5;
int kneld = 2;
boolean jid = true;
double rustwa = 5.0;
boolean saud = false;
boolean ce = true;
int hass = 8;
double sepo = 5.0;

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

8 != 5 || 3 > mesirm && me <= e || 3 != kneld == (!jid && rustwa != 7 && saud != ce) == (hass != sepo) || 5 != 4

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: