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 blelsi = 7;
int spoi = 7;
double apprio = 1.0;
int crormir = 5;
double hi = 3.0;

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

blelsi + 5 * 1 - 0 - 7 % 3 / (spoi % apprio / crormir + 2 + hi) / 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean abia = false;
double ouirch = 2.0;
int ecass = 1;
int dercrod = 4;
int fecce = 8;
boolean contphaos = true;
double dassglank = 5.0;
double pe = 2.0;
double suilin = 5.0;

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

4 == 9 || abia && !(5 == 1) != !(!(ouirch <= ecass)) && !(5 > dercrod) || 3 >= 6 || 7 < fecce && contphaos && 4 > dassglank || pe != 6 == (4 != suilin)

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: