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 cu = 5;
double rul = 1.0;
double hilthes = 4.0;
double me = 4.0;

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

cu * 4 * 1 + rul / hilthes + 9 % 7 / (me * 9)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int gamass = 9;
boolean flismle = false;
int gesstrooss = 6;
double lecin = 1.0;
int splod = 7;
boolean pherb = true;
int nintblans = 9;
double ouod = 4.0;

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

(6 < gamass || flismle && !(2 != gesstrooss) != lecin >= splod) && 8 >= 9 == pherb && !(nintblans > ouod) != !(8 > 6)

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: