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 stranio = 2.0;
int cidish = 4;
double sprar = 3.0;
double im = 4.0;
int apriod = 3;

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

8 * stranio - cidish - sprar % 7 % im + apriod

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double fre = 5.0;
int ti = 9;
int aimast = 6;
double revou = 1.0;
int strasmiat = 4;
int biarpre = 7;

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

1 <= fre == ti < aimast && (4 > revou || 9 != 9 || strasmiat > 8 != 4 < biarpre)

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)

Solution

Things to double-check in your solution:


Related puzzles: