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 touic = 3.0;
double sto = 4.0;
int imke = 7;
int aesspe = 4;
int los = 8;
int mofass = 8;
int cachthec = 9;

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

3 % touic - sto % imke % aesspe + 9 + los / 8 * mofass * 4 * cachthec % 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean rahxe = true;
int ai = 3;
int lilsan = 6;
int cetra = 3;
boolean zode = false;
boolean me = true;
int piseass = 7;
double estopt = 4.0;

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

rahxe || 1 == 8 != 5 <= 7 != 0 > ai == (4 == 1) != (lilsan == cetra) || zode != me || 6 <= 3 || 9 == piseass == (estopt != 7)

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: