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 gintsol = 5;
int towar = 4;
int fiol = 6;

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

(gintsol / 3 * towar - 5 / 6 - 8 - fiol - 8) % 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int mier = 7;
int ur = 8;
double candcerk = 5.0;
double trimi = 3.0;
int idfliass = 6;
double ussmint = 2.0;
double er = 4.0;
double eiism = 1.0;

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

mier != 5 && (1 <= ur || !(3 == 1) && candcerk >= 1 == trimi < 4) != !(6 < 0) == idfliass >= ussmint != !(er < eiism)

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

Solution

Things to double-check in your solution:


Related puzzles: