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 uc = 2.0;
int rint = 4;
double il = 4.0;
double tion = 1.0;
int psul = 2;
int e = 9;
double thurang = 1.0;

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

uc - rint * il - 5 % 7 % tion % 6 % 5 * psul - e / thurang

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean anjo = false;
double flass = 3.0;
boolean umcre = true;
int chrerno = 9;
int i = 6;
int eun = 2;
double ucpi = 3.0;
int o = 3;
double sphol = 3.0;
double shounca = 5.0;
int basssio = 2;
int ga = 7;

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

anjo != (flass != 0) || (umcre != (0 != chrerno) && i > 9) == (eun != ucpi) == 7 < o != sphol >= 7 && shounca == 4 != basssio < ga

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: