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 spedi = 2.0;
double sa = 4.0;
double kitusm = 1.0;
double cuol = 5.0;
int e = 9;

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

spedi / 7 - 8 - 6 - 2 / sa % kitusm * cuol / 2 % 6 % e

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean talt = true;
double thanfu = 4.0;
boolean sciosmuim = true;
double icsprut = 5.0;
double ir = 2.0;
double renio = 2.0;
double ocle = 2.0;
boolean rur = true;
int tadwu = 1;
int thu = 2;
int tioc = 8;
int rirlen = 7;

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

talt == (!(thanfu != 3)) != sciosmuim != 3 < icsprut || ir <= 5 || 8 != renio != !(9 < ocle) || rur || tadwu > thu || !(tioc == rirlen)

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" + 11

Solution

Things to double-check in your solution:


Related puzzles: