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 qasec = 9;
double pena = 2.0;
double de = 3.0;
double hioc = 4.0;

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

qasec - 1 / pena + 1 * 2 * 0 % 7 + de * 5 + hioc

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ofe = false;
double poing = 3.0;
int ohan = 2;
double cring = 2.0;
int peshma = 1;
double urm = 4.0;
double poul = 5.0;
boolean nenti = true;
int sowioght = 9;

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

ofe == poing >= ohan != cring >= peshma != !(!(9 > 1)) || 3 != urm && poul == 7 && nenti || sowioght <= 4 != !(0 < 0)

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: