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 ioussgarn = 2.0;
int mael = 7;
int es = 3;
int un = 4;
int gluss = 3;
int edud = 6;
double pu = 4.0;
double polchur = 3.0;
int sesmpent = 7;

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

ioussgarn % mael / es / un % 2 - gluss / edud + pu / 7 % polchur * sesmpent

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ca = 7;
int sungbeong = 3;
double nois = 1.0;
double envoc = 4.0;
boolean psesmoin = true;
int e = 4;
double neli = 4.0;
int cild = 3;
boolean qu = false;
int hidirch = 9;
double stea = 4.0;

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

ca <= sungbeong || !(nois >= envoc) || psesmoin || (2 != 4 == (!(!(e == 8))) != 8 <= neli == (cild == 9)) != qu && 8 >= hidirch != stea < 8

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: