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 gidvie = 4;
int karrar = 5;
int wrasma = 9;
int es = 8;
int an = 3;
int vo = 1;

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

8 - gidvie + karrar / 2 + 3 % wrasma % es / an + 8 / vo / 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ee = 1;
boolean raspmoung = false;
boolean trus = false;
double lalva = 5.0;
double adlost = 1.0;
int o = 3;
boolean kontloss = false;
boolean rubre = false;
boolean mup = true;

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

ee >= 0 != raspmoung == 4 > 8 != trus || !(!(lalva >= 0)) && 9 >= adlost == 8 <= o != !kontloss && !rubre && mup

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: