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 pa = 2.0;
double tre = 4.0;
double sies = 2.0;
double is = 2.0;

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

8 * pa * 7 * 6 + 9 / (tre / 8 - sies / 1 * is) - 9 - 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double sco = 1.0;
double puscrics = 1.0;
int spe = 7;
int scihur = 1;
double leco = 3.0;
double geaw = 2.0;
double fisoc = 5.0;
boolean oirgli = false;
double eder = 5.0;
int ca = 2;
double eattu = 3.0;
double ud = 5.0;

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

sco == puscrics && !(spe < scihur) && !(leco <= 3) || geaw >= fisoc && oirgli && 8 <= 9 == 8 < 5 != !(eder > 0) && 9 >= ca == 7 > eattu == (9 == ud)

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) + 11 + 12

Solution

Things to double-check in your solution:


Related puzzles: