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 bilto = 4.0;
double eposm = 3.0;
double phitou = 4.0;
double a = 5.0;
int chereng = 8;
double shoustid = 1.0;
int su = 9;

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

bilto % eposm + 4 / phitou * 6 * a * chereng - 2 * shoustid / su

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int thior = 5;
double eiss = 2.0;
boolean tiswa = true;
int cula = 1;
int clur = 3;
double fuscrur = 3.0;
int o = 7;

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

1 >= thior && !(eiss < 0) == !tiswa == 7 >= 0 || cula <= 0 || !(clur < 2) != (3 != 5) || 4 <= fuscrur == o >= 2

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: