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 ias = 1.0;
int iaccac = 1;
int du = 3;
int ti = 4;
int wilkel = 1;
int ku = 7;
int pistull = 6;
int reass = 9;

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

3 / ias + iaccac % 4 - du % ti / wilkel % (ku * 2 % pistull * 1 + reass)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean gajes = true;
int mua = 2;
int ici = 7;
double is = 1.0;
boolean blosri = false;
double ui = 4.0;
int asm = 4;
int reafi = 8;
double cu = 3.0;
boolean sousm = true;

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

gajes && mua > ici && 5 >= is && blosri || ui < 8 && asm <= reafi && 0 == 0 != !(1 >= cu) && sousm == (5 != 4) != (5 != 7)

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: