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 dio = 4;
int penid = 2;
double skoto = 2.0;
double whu = 2.0;
int pesca = 9;
double i = 2.0;
int ha = 7;
double plopt = 2.0;

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

dio * penid % skoto % 4 / 5 * whu / 4 / pesca + 9 * (i % ha * plopt)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int bie = 2;
int kreous = 1;
int spinkphel = 6;
double apran = 2.0;
int ecrou = 9;
double shesin = 5.0;
int te = 4;
int trourm = 2;
double tralfid = 3.0;
double blor = 3.0;
int renber = 7;
boolean prepni = false;
double ad = 2.0;

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

0 != bie && kreous != spinkphel != 2 < apran != (ecrou == 3) && shesin <= te || !(trourm >= tralfid) && 8 == blor || 5 <= renber && prepni != (!(ad == 4)) || 5 <= 7

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: