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 cangsi = 9;
int e = 6;
double i = 3.0;
int cirs = 6;
int gelo = 7;
double ra = 4.0;
int ae = 3;

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

(cangsi % 4 % 6 * e / i + 4 - 5 / cirs) * gelo * 0 * ra / ae

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int posor = 1;
boolean glizoox = true;
boolean feresh = true;
boolean hawhon = false;
double ece = 4.0;
int corpaght = 2;
double turtro = 3.0;
boolean maswhed = true;
boolean ligus = false;

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

6 < 4 != 8 < 0 && 9 != posor || glizoox == feresh || 7 == 4 == hawhon != ece >= corpaght || turtro != 8 && maswhed || ligus

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: