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:

double fahor = 4.0;
int cissbi = 7;
int ni = 6;
int nicas = 6;
double ir = 3.0;

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

fahor * cissbi / ni / 2 - (nicas / ir - 0 - 7 * 0 - 1 + 1)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double oaoct = 1.0;
boolean hachlu = false;
int salstal = 6;
int hecreash = 8;
double parfrusm = 2.0;
int te = 9;
boolean zora = false;
double vodhi = 1.0;
int proent = 9;
int hetrox = 4;
int be = 6;
boolean dalgir = true;

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

oaoct >= 1 != hachlu != (salstal <= 9 && hecreash == parfrusm) || !(te < 8) && zora || 0 < vodhi && proent > hetrox || !(be > 5) || dalgir

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: