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 smud = 5.0;
double kosmes = 4.0;
int duca = 1;
double missid = 5.0;
int a = 6;
int throodve = 5;

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

smud + 2 - (kosmes + duca / 6 + 6 + missid) % a / throodve

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int sa = 1;
double koc = 4.0;
int ent = 9;
boolean spiara = true;
double milwa = 5.0;
int essmis = 3;
boolean probaunk = true;
int deersun = 4;
boolean dacrhe = true;

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

sa >= koc == ent > 0 == spiara || milwa >= essmis != !(5 < 6) == (!probaunk != 4 >= deersun && !dacrhe)

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: