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 prioscan = 2;
int is = 4;
int hetro = 8;
int reir = 2;
double hur = 4.0;
double issil = 1.0;

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

prioscan * is * hetro * reir % hur / 4 + issil - 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int nestcom = 7;
int oussgi = 5;
boolean qi = false;
boolean ed = false;
double pe = 4.0;
int cer = 7;
double grantfin = 5.0;
int lasschas = 9;
int xer = 2;

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

nestcom == oussgi || qi != ed || 7 > 7 == 0 > pe && cer == grantfin || lasschas >= xer

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

Solution

Things to double-check in your solution:


Related puzzles: