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:

double e = 5.0;
int ropran = 4;

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

2 - e - 5 * ropran % 9 / 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean sesu = false;
double ihti = 4.0;
double xado = 5.0;
int pranpain = 5;
double landar = 4.0;
double ailce = 5.0;
double maiswo = 4.0;
double brampec = 4.0;

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

(sesu != ihti > xado == (pranpain == landar)) || 8 == ailce || maiswo == brampec

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

Solution

Things to double-check in your solution:


Related puzzles: