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 fo = 3.0;
int iss = 1;
double padloc = 5.0;
double necs = 2.0;
int se = 8;
double ma = 5.0;
double featbon = 4.0;

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

fo + iss % padloc / 3 / 8 % 4 % necs + se / ma / featbon + 8 % 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int aeu = 2;
int stirne = 8;
boolean terd = true;
boolean oa = false;
boolean ce = false;
double ditherm = 1.0;
int a = 9;
boolean dant = false;
boolean saio = false;
double samsieng = 3.0;
boolean ga = true;

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

aeu != stirne && terd == oa || ce || 9 <= 4 && 6 == ditherm != 0 <= a && dant == saio && 4 < samsieng && ga

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: