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:

double wuphston = 2.0;
double simn = 3.0;
int e = 5;
double esa = 2.0;
double boont = 1.0;
int bimbpo = 7;

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

1 - 1 * wuphston + 7 - simn - 4 * e / esa % 5 + 6 % boont + bimbpo

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean oste = false;
boolean pamsac = false;
int gler = 9;
int segi = 4;
double ur = 5.0;
boolean igeng = false;
int cenda = 2;
int oltrer = 4;
int pseache = 5;
double dengut = 2.0;
boolean therred = true;

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

!oste == pamsac || 0 > gler != segi >= 7 != 5 > ur != !!igeng || cenda != 8 == !(oltrer > pseache) && dengut < 1 || 7 != 5 != therred

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: