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 io = 1.0;
double iossi = 3.0;
int besto = 4;
double ocro = 4.0;

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

0 - 8 % 3 - 6 / (io / iossi - besto) - 2 / ocro

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double dasse = 1.0;
int pra = 4;
boolean asuc = true;
int nenpsast = 5;
int cacsmis = 6;
boolean iss = true;
boolean ae = true;
double paicceth = 3.0;
int xa = 1;
int ea = 6;
double ukoct = 5.0;

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

dasse > 6 && pra >= 7 == asuc == nenpsast > cacsmis == iss != ae || paicceth != xa && ea != ukoct

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: