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 pran = 4;
double mesu = 5.0;
double cretchwu = 2.0;

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

(2 + 9 * 4 * 9 * 0 + pran - 7 - mesu - 6 % 1) + cretchwu + 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double crasish = 3.0;
double swardar = 4.0;
int sadpac = 1;
double mieral = 1.0;
boolean dowes = false;
int sisa = 1;
double po = 5.0;
boolean prioph = false;
int nesblie = 6;
int assspust = 7;

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

crasish < swardar != (sadpac != 6) && mieral == 1 && 8 < 7 != dowes && sisa > po != 7 < 1 || prioph && 5 >= 1 == nesblie >= 6 == 1 <= assspust

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: