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 mo = 4.0;
int liic = 3;
int entthi = 8;
int boad = 3;

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

2 + 7 / mo / (8 / liic / entthi) * 3 + 5 % 1 / 9 + boad

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int jaled = 6;
double me = 4.0;
int peaploo = 9;
boolean enbos = false;
int traismerch = 2;
double pri = 1.0;
boolean mesol = true;
int rengan = 2;
boolean jeste = false;
boolean wrun = true;

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

4 != 8 == 6 <= jaled == me > peaploo || enbos != (9 != traismerch) == (!(pri == 6)) && mesol != rengan < 0 || jeste != wrun

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: