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 fihphir = 8;
int sotsia = 4;
double moen = 1.0;
double fa = 4.0;
int egemp = 7;

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

fihphir + 0 - (1 % sotsia % moen + 3 / 2 * 8 - fa) + egemp

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double e = 2.0;
double spim = 3.0;
boolean ris = true;
int a = 9;
double po = 3.0;
boolean is = false;
double kretin = 1.0;

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

e == 8 == (spim > 7 && ris && !(6 > 9)) == 9 <= 4 && !(1 == 7) == a <= po == is || 8 != kretin

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 + 10

Solution

Things to double-check in your solution:


Related puzzles: