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 latre = 3;
double un = 5.0;
double a = 3.0;
double pelmess = 1.0;
int vun = 8;
int hasic = 4;
int tiic = 7;
double so = 4.0;

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

latre * un - 5 * a * pelmess * 8 % vun - 9 + hasic + (1 * tiic) - so

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double prunun = 1.0;
int piasor = 7;
boolean cina = false;
boolean troisir = false;
double phenger = 3.0;
boolean drurbe = true;
int be = 5;
int sqir = 3;
int cecan = 8;
double cebeurd = 4.0;

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

!(prunun != 6) == 8 < 5 == piasor <= 7 || (cina != troisir == phenger < 2 == drurbe && !(be != 3) != sqir < 1) || cecan == 1 || cebeurd <= 6

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: