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 ce = 6;
int spilpse = 8;
double irre = 3.0;
double ca = 3.0;
double phri = 4.0;

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

ce + spilpse + irre / 7 % ca * 5 % phri - 8 % 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean oss = true;
int neomod = 3;
double truned = 5.0;
boolean nent = true;
int sningooss = 9;
int deo = 2;
double no = 3.0;
double wigru = 5.0;
int spiaris = 9;
double taci = 2.0;

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

oss && 6 < neomod || (7 < truned && nent != !(3 > sningooss) || !(deo >= no) != (3 == wigru) != spiaris > taci)

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

Solution

Things to double-check in your solution:


Related puzzles: