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 esped = 3;
int io = 5;
double is = 4.0;
double o = 3.0;
double hopuiss = 3.0;
int vi = 7;

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

esped % (4 % 2 - 6 - 6 / io / 1 + is) - 9 * o - hopuiss - vi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ni = 3;
int girkou = 8;
double arsi = 5.0;
int e = 4;
int hisptosm = 4;
boolean ma = false;
int simeiss = 8;
double mo = 2.0;
double ne = 1.0;
int unhar = 9;
double hur = 5.0;
double ickbra = 3.0;

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

6 >= 8 || ni >= girkou && arsi <= e != (1 == hisptosm) == ma != 2 >= simeiss || mo > 5 && 7 != 9 && ne <= unhar != 9 <= hur != (ickbra != 1)

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: