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 nisheoull = 9;
double caesa = 5.0;
double tiossju = 1.0;
double graru = 5.0;
int rakont = 3;
int i = 6;

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

nisheoull * caesa - 4 * 0 / tiossju % 8 * graru - rakont * 3 % i

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int e = 5;
int blosmost = 9;
boolean eol = true;
int spesmspru = 9;
boolean stom = true;
double ri = 5.0;

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

e < 9 && 1 == 0 != 3 <= 6 == 6 <= blosmost == 6 >= 8 && eol != spesmspru <= 9 == !!stom == !(3 >= ri)

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

Solution

Things to double-check in your solution:


Related puzzles: