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 jid = 7;
int cegedd = 2;
int a = 3;
double vogbon = 3.0;
double olast = 3.0;
int psaoc = 1;

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

jid + cegedd - 2 + 2 % 6 * a * vogbon - 6 - olast / psaoc + 0 - 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean swotri = false;
int hassa = 4;
double osriar = 3.0;
double u = 2.0;
boolean daxeouck = false;
double snacu = 3.0;
int on = 7;
int frashgil = 3;
int ikiss = 7;
int hesm = 5;
boolean inad = false;

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

swotri || 1 <= 0 != !(hassa > 1) || (osriar >= u == daxeouck && 7 <= 1 && snacu > on) || !(7 < frashgil) && !(9 >= 3) && ikiss >= hesm || inad

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

Solution

Things to double-check in your solution:


Related puzzles: