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 uic = 4;
double sclircand = 2.0;
double pri = 4.0;
int irgant = 1;
int onga = 8;
int osdro = 5;

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

uic / sclircand - 9 + pri * 2 / 3 + 8 / irgant + onga / 7 * osdro

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean droustgra = false;
int pheoustnom = 2;
double pulon = 2.0;
double muhin = 3.0;
double feciss = 1.0;
boolean fric = false;
boolean unge = true;
boolean miaid = true;
boolean paghtpre = false;

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

droustgra && 5 != 1 != (pheoustnom == pulon) || !(!(muhin > feciss)) == fric == (7 == 2) && 5 == 2 || unge || miaid == paghtpre

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"

Solution

Things to double-check in your solution:


Related puzzles: