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 maea = 6;
double pepsa = 2.0;
double psubal = 5.0;
int flintpa = 3;
int o = 6;
int phai = 9;

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

maea % 5 - (pepsa / 6 + 7 - psubal % flintpa) / o * 0 - 3 * 7 % phai

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ilse = 2;
double lial = 1.0;
boolean halroont = true;
int fescis = 4;
double didpap = 1.0;
int esmme = 3;
double essoh = 1.0;
double isar = 1.0;
boolean cropt = true;
double on = 4.0;
double sosnaur = 1.0;
boolean e = true;
double co = 1.0;

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

ilse >= lial != halroont || 1 < fescis == ((6 != didpap) == (esmme == 5) || essoh > 5 == isar <= 5 && cropt || on >= sosnaur != !e) && 5 < co

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: