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 bestheld = 4.0;
int eahe = 8;
double cangsa = 3.0;
double nirk = 5.0;
int sa = 6;
double cinpin = 3.0;

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

bestheld - eahe + cangsa + 6 / 5 % nirk + sa / cinpin

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double co = 4.0;
boolean vit = false;
double ofe = 2.0;
double a = 4.0;
int hesshass = 1;
int witcob = 2;
int rocro = 8;

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

4 <= 0 == !(2 >= 2) || 5 >= co == vit && ofe != a == hesshass > 0 && witcob >= rocro

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: