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 pe = 5;
double hi = 5.0;
double noidce = 1.0;
double brai = 3.0;
int tu = 2;

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

pe * (1 - 6 / 7 * hi + noidce % 8) - brai / tu / 6 * 5 - 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean biliecs = true;
boolean vaun = true;
double punmess = 2.0;
int fecmes = 8;
boolean enel = true;
boolean glun = false;
double tuqa = 3.0;
boolean shung = true;
double mi = 1.0;

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

biliecs != 8 >= 0 || vaun || !(9 <= punmess) != !(3 >= fecmes) && enel || glun != (!(tuqa != 9)) || !(8 != 4) || shung != (mi == 7)

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: