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 ent = 3;
int ic = 9;
int ce = 9;
double ra = 5.0;
double ruinsost = 5.0;
int mo = 9;

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

ent - ic * 8 * 7 % ce % 8 / 7 / ra - 5 + ruinsost + mo * 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean stilen = false;
double hodstas = 1.0;
double ede = 5.0;
int scearci = 4;
int chent = 6;
boolean i = true;
boolean signcal = true;
double id = 2.0;
int ciss = 9;
double sosm = 3.0;
int nepros = 4;
double bisi = 2.0;

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

stilen || 2 > 7 == 3 >= 0 && hodstas < 1 == ede <= scearci != chent > 4 || i == signcal != (7 != id) != (ciss == sosm) && nepros != bisi

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: