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 numerm = 3;
double chastspas = 1.0;
int greo = 1;
int psava = 8;
double go = 2.0;
int iaral = 2;
int heang = 6;

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

numerm + chastspas * 5 / (3 % 1 + 8 * 6) % greo * psava / go + iaral / heang

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ciong = 2;
double rac = 2.0;
double pe = 1.0;
int uw = 4;
boolean sponi = true;
int gerstross = 3;
int satal = 6;
double rocwheur = 4.0;
boolean blesscrir = true;
boolean femtraent = false;
int or = 5;
int tedsqul = 3;
int ikiss = 9;

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

5 == 9 || ciong == rac == pe <= uw != !sponi && 9 != gerstross && satal >= rocwheur != blesscrir && !femtraent && 3 < or || 8 >= 7 && !(!(tedsqul > ikiss))

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: