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 ecral = 2.0;
int neis = 1;
int ne = 8;
double degplai = 3.0;
double cleabaus = 3.0;
int poushe = 7;
double endo = 3.0;

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

1 % ecral / neis + 3 * ne - 2 + degplai * cleabaus - 5 - poushe / endo

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double spinpod = 3.0;
double houdmas = 1.0;
int hecras = 4;
int cemeng = 1;
boolean rosmdron = false;
double munnirds = 3.0;
boolean essrof = false;

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

spinpod <= 0 && houdmas != hecras && 0 <= 2 == !(4 < cemeng) && 3 >= 3 && (rosmdron != 9 <= 6) || 7 == munnirds && 7 <= 3 != essrof

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: