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 huintpe = 1.0;
double onbeos = 3.0;
double cidpnusm = 5.0;
double tightvi = 4.0;

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

2 + huintpe * 0 + 3 * onbeos * 1 * cidpnusm / tightvi - 9 / 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double pe = 1.0;
boolean er = false;
int at = 3;
int cusbesm = 5;
double celount = 3.0;
int ent = 7;
double chlesh = 3.0;
int lessne = 8;
int preoultink = 8;

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

!(2 <= pe) == er != (at < 6 != (cusbesm == 6) || 6 != 8) == (!(1 == celount)) == (ent == chlesh) && 3 < 6 && !(lessne == preoultink)

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: