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 racmit = 9;
double milheen = 5.0;
int pacsdioff = 8;
int kiwho = 6;
int ica = 2;

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

2 * 2 / 4 - racmit % 8 % milheen * 8 % pacsdioff + 7 * 6 / kiwho / ica

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double nect = 2.0;
double ib = 2.0;
int boint = 5;
int i = 3;
double thoussti = 1.0;
double hicscism = 3.0;
boolean ii = true;
int cer = 1;
double be = 3.0;
boolean prar = true;
boolean laag = true;

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

!(2 >= nect) || 4 == ib != !(boint > 1) == i > thoussti != hicscism < 9 && ii || 4 >= cer || be >= 7 || 7 > 1 && prar && !laag

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: