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 prelo = 3.0;
double vora = 2.0;
int lesstak = 6;
int fe = 3;
double pradzus = 1.0;
int ri = 9;
double caidrhal = 1.0;

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

prelo + 3 - vora * 9 - lesstak - 9 + fe % pradzus / 6 % ri / caidrhal

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int duanhai = 3;
int pe = 7;
boolean oth = false;
double cer = 2.0;
double vece = 2.0;
boolean triphi = true;
double guel = 2.0;
double ce = 4.0;
boolean nuab = false;
boolean lun = false;

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

7 > duanhai != (pe == 1) && oth || 5 == cer != ((!(3 == vece)) && triphi != guel < 5 || ce == 5 && nuab == lun)

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: