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 smi = 8;
double striddaun = 4.0;
int ritden = 6;
int lingren = 2;

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

smi + 2 - 6 * (6 + 7 * striddaun * ritden) % lingren

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean bimhe = false;
boolean ossglad = true;
double ucish = 2.0;
int ce = 9;
boolean suario = false;
int o = 2;
double tre = 4.0;
int phin = 9;
int nec = 7;

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

bimhe != ossglad != (ucish == ce) != suario != (2 == o) || 3 <= tre || phin == nec

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"

Solution

Things to double-check in your solution:


Related puzzles: