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 sarte = 8;
double hiirm = 5.0;
double priasal = 2.0;
int olbess = 4;
int ou = 5;
int aspe = 4;

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

(sarte % hiirm + 0 - priasal + olbess) * 7 + 4 - 8 % 5 + 9 - ou % aspe

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int qiah = 7;
double jispol = 2.0;
boolean ludea = true;
double woda = 4.0;
double atrol = 4.0;
double it = 2.0;
boolean eannat = false;
boolean cidqet = false;

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

(qiah > jispol && ludea && 3 > woda != !(8 > atrol) != !(6 < 7) && it <= 0 || 5 == 4 == 3 < 9 && 8 <= 4) != !eannat || cidqet

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: