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 figic = 5;
double hibos = 3.0;
double flein = 2.0;
double pel = 3.0;
int iscirm = 1;
double rimpbon = 4.0;
double se = 3.0;

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

4 / 2 % figic * 6 * hibos + flein % pel * iscirm + rimpbon * 5 * 6 % se

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double u = 5.0;
double prinid = 2.0;
double bi = 3.0;
int cioldlost = 9;
int haphis = 3;
double cuidell = 1.0;
double kissca = 1.0;
boolean iarca = false;
int denass = 8;
int koma = 1;
boolean qi = true;
double pran = 5.0;
int unhal = 1;
boolean ofe = true;

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

u == prinid && bi == 4 || cioldlost != haphis || !(7 > cuidell) || 5 >= kissca == !!iarca && denass <= 6 && 8 == koma || qi == (pran != unhal) && ofe

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: