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 e = 3.0;
double treaci = 1.0;
int thada = 1;

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

5 % e * 0 / 1 * treaci * thada % 6 * 5 - 7 % 9 + 9 % 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean dant = false;
int uiol = 1;
double mocmem = 3.0;
int ceor = 8;
boolean su = false;
int mocio = 4;
int sor = 2;
int iasai = 3;
double depmong = 4.0;

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

5 >= 1 || dant && 1 > 9 != 3 < uiol != (mocmem == 3) == (ceor == 2) && su || mocio <= sor == 2 > iasai && 3 == 3 != (depmong != 3)

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: