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 en = 2;
double fourqe = 4.0;
double suphi = 4.0;
int seadgo = 3;
int te = 1;
double heswed = 5.0;

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

2 - (en % fourqe % 4 - suphi) * seadgo + 2 % te * 2 % 9 + heswed

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean merlil = true;
int riiol = 1;
int huacfen = 8;
int kosu = 4;
int unger = 5;
double mo = 4.0;
int anri = 7;
boolean eriart = false;
int tio = 1;
double ti = 1.0;
boolean i = false;
int buisban = 8;
double eb = 4.0;

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

!merlil != riiol < huacfen != !(kosu <= 2) == (unger == 3) != mo > anri == eriart && tio < ti != i || !(!(8 == buisban)) && 7 < eb

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

Solution

Things to double-check in your solution:


Related puzzles: