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 gua = 6;
int prir = 8;
int clercoun = 9;
int onporch = 3;
int di = 7;
double snest = 5.0;

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

(gua - prir / 5 / clercoun % onporch % di) * snest / 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double a = 2.0;
int rhunscec = 7;
double oac = 3.0;
double haswi = 2.0;
boolean inhall = false;

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

1 == a && (!(rhunscec != oac) == 3 <= 5 || !(8 < 4) || 3 != haswi || 4 != 7) == inhall

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

Solution

Things to double-check in your solution:


Related puzzles: