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 iaslo = 4;
double bonpis = 5.0;
int se = 3;
int illve = 7;
int pattol = 4;

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

9 - (5 / iaslo - 3 / bonpis * 5 % se) + 0 / illve * 7 / pattol - 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double paecon = 3.0;
double i = 3.0;
double pissping = 3.0;
int tengria = 2;
int re = 8;
double pe = 3.0;
int ia = 5;
double pne = 1.0;
int fo = 9;
double u = 1.0;
int prun = 4;
double intsar = 1.0;
int e = 2;

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

!(0 == paecon) || 7 > 9 == (1 <= i == !(pissping <= tengria) && re >= 0) == !(6 < pe) || ia == pne != (fo == 1) && !(0 == 2) == u > prun || intsar == e

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: