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 fliddi = 5.0;
double ha = 1.0;
double se = 3.0;
double kneasming = 2.0;
double co = 2.0;
double daar = 5.0;

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

0 / fliddi - 4 * ha - 9 + se / kneasming % co * daar

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int clun = 3;
boolean tumon = false;
int o = 3;
boolean pestrea = false;
double vunt = 5.0;
int fe = 4;
double le = 3.0;
boolean cumint = false;

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

8 == clun && tumon || !(o < 6) && !pestrea || 5 < vunt || fe == le || 3 <= 7 && cumint

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: