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 usdit = 7;
int udpipt = 6;
int mieched = 2;
double merhios = 4.0;
int telcoc = 9;
int wintfleng = 7;
int ji = 1;
double wancuc = 1.0;
int uch = 8;

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

usdit - udpipt - mieched + merhios / 7 + telcoc / wintfleng / (ji * wancuc - uch) - 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double juangosh = 5.0;
int aiss = 5;
int ciod = 2;
double id = 2.0;
int banji = 3;
double scocats = 1.0;
double i = 3.0;
int cestec = 6;
boolean miosse = true;
double oss = 1.0;
boolean malsi = false;

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

0 != juangosh != (6 != aiss) != ciod >= id != (banji == 9) && (!(!(9 != 5)) && scocats >= i != !(6 < cestec)) || miosse != !(oss >= 9) == malsi

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

Solution

Things to double-check in your solution:


Related puzzles: