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 pillish = 1.0;
int oo = 6;
int ee = 8;
int margru = 3;
int kounnell = 9;
double cesglus = 5.0;
int jiod = 2;

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

9 % 5 + pillish * oo / 2 + ee * margru / 9 % kounnell % 4 - cesglus * jiod

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double zeerwal = 4.0;
int tiacpus = 3;
int bighbor = 2;
boolean ciciud = true;
boolean guon = false;
boolean iar = false;
int uaton = 5;
int a = 5;
int elcol = 5;
int ra = 5;
double dertno = 1.0;
int i = 5;
int mocved = 1;

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

(zeerwal >= 5 || tiacpus < bighbor == ciciud || !guon == iar == (7 != uaton) || 3 <= 5) && !(a <= elcol) != !(1 > ra) == (dertno == i) || mocved >= 1

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: