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 se = 2;
double galvi = 3.0;
double guree = 4.0;
double aggrel = 3.0;
double mii = 4.0;
double i = 4.0;

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

9 + 4 - se + 4 * (galvi - 6 + guree + aggrel * 8) % 2 % mii % i

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double plommoos = 4.0;
boolean sti = true;
int ughtchi = 5;
int esthack = 6;
int we = 3;
int untcoss = 5;
boolean sopis = true;
int clen = 9;
boolean puhe = true;
boolean asmkan = false;

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

!(3 < 9) || 4 >= plommoos || sti || (ughtchi < esthack || 9 > 7 != !(we >= untcoss) == 2 > 3 && sopis || !(9 <= clen)) && puhe != asmkan

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: