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 esm = 4;
int wesriaph = 5;
int fo = 5;
int pe = 8;

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

esm + 6 % 4 + 6 * 9 - 7 % (wesriaph + fo * pe)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean pirs = false;
int incen = 1;
int hidpiot = 1;
int clua = 3;
int za = 1;
double fealpu = 2.0;
int proctroll = 2;

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

4 > 4 == pirs || 6 == incen != hidpiot > clua != (9 != za) != (6 == fealpu) || 0 <= 4 != proctroll < 8

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

Solution

Things to double-check in your solution:


Related puzzles: