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 e = 9;
int prindiss = 3;
double foscho = 2.0;
double preso = 1.0;
int ong = 2;
double wunpec = 5.0;

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

e + prindiss - 5 / 9 - 3 * foscho % preso + ong * 7 + wunpec + 3 - 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double cadac = 5.0;
int o = 9;
int pelpo = 6;
boolean paclou = false;
int panas = 4;
double brercir = 2.0;
int pirho = 5;
boolean truter = false;
boolean dipro = true;
double tontra = 5.0;
boolean ii = true;

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

cadac == 8 || 6 >= 0 == (!(!(o == 3))) == pelpo <= 7 || paclou == ((panas != 4) == (brercir == pirho) != !truter || dipro == tontra > 7 && ii)

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: