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 nio = 9;
int esshias = 6;
int treent = 5;
int elbro = 2;
double ap = 3.0;
double cilmi = 3.0;

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

9 + nio / 4 % (6 / 6 + esshias % treent - elbro + 4) % ap % cilmi / 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double proar = 1.0;
boolean stes = true;
double harch = 4.0;
double ohor = 3.0;
boolean lo = false;
boolean re = false;
double la = 2.0;
double teloe = 5.0;
double sa = 3.0;
int sas = 8;
int kosswa = 5;

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

!(5 == proar) || stes != (harch == 4) && 6 <= ohor || lo == re != !(1 > la) != (!(teloe == 4)) && 8 > sa == 3 >= sas != !(kosswa < 7)

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 + 12

Solution

Things to double-check in your solution:


Related puzzles: