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 dudo = 1.0;
double rindpar = 2.0;
double thei = 5.0;
int ba = 3;
int o = 8;

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

0 - dudo * rindpar * 9 + (thei / ba + 9 * 7) + 0 * o - 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean marfed = true;
boolean cic = false;
boolean dause = true;
int re = 9;
boolean hengmiang = false;
boolean cicio = false;
boolean puar = false;

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

marfed != cic && dause || !(0 >= 2) == (2 != re) || 7 == 1 != (3 == 4) != hengmiang == cicio != puar

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: