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 bocrol = 5.0;
double biel = 5.0;
int preniong = 9;
double perte = 4.0;

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

bocrol / 3 + 8 - biel / preniong - 1 + perte

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double pof = 1.0;
int schoa = 9;
boolean elim = true;
int ne = 2;
int pucs = 7;
boolean om = true;

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

pof >= schoa && elim != (ne == pucs) && 8 > 1 == om != 7 > 6

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

Solution

Things to double-check in your solution:


Related puzzles: