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 enjol = 1;
double he = 1.0;
double al = 1.0;
double ingchli = 2.0;
int ivel = 2;

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

1 + 5 % 5 - 0 % (enjol * 3 * he) * al % ingchli + ivel - 7 * 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int psasnant = 9;
double pessclar = 2.0;
int sosal = 7;
double piok = 1.0;
boolean thangrimn = false;
double as = 4.0;
int cadme = 1;
double qezal = 3.0;
boolean ed = true;
boolean a = true;
int acsach = 3;
boolean boi = true;

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

psasnant != pessclar && sosal > 2 == 5 <= piok != thangrimn && 3 >= as != !(cadme < qezal) != ed && a == (2 != 7) || 6 < acsach == !boi

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: