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 ciosfoft = 1.0;
double en = 2.0;
int lanspa = 9;
double psosh = 1.0;
double shis = 2.0;

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

ciosfoft % en * lanspa * 9 / psosh % 4 / 7 + shis

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double pacvec = 3.0;
double ia = 2.0;
double puounid = 4.0;
double cuila = 4.0;
double micou = 3.0;
double pased = 2.0;
double wroil = 4.0;
double id = 4.0;
int ucor = 7;

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

8 > pacvec == ia >= puounid == 4 >= cuila && 4 < micou && pased == 3 == wroil >= 5 && id < ucor

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: