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 ramwel = 9;
double sheir = 1.0;
int er = 7;
int pupic = 5;
int de = 1;
double aspref = 1.0;
double clis = 3.0;

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

ramwel - sheir % er % 6 / pupic - 2 - de + 9 / aspref * 3 / clis

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double pripi = 5.0;
boolean napec = true;
int la = 3;
double or = 5.0;
int prent = 3;
double pakusm = 4.0;
double ri = 4.0;
boolean chrirpre = true;
int liwklun = 4;
int fe = 3;
boolean rhen = true;
boolean geqon = false;

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

pripi >= 2 && napec == la <= 1 != (4 == or) || (1 >= prent != (pakusm == ri) && chrirpre == liwklun <= fe != rhen != geqon)

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: