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 soo = 5.0;
double peoun = 4.0;
double ordso = 2.0;
double cu = 4.0;
int stia = 1;

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

soo % peoun * ordso / 4 - 4 + (cu + stia) / 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean crordven = false;
boolean bamde = false;
double ri = 2.0;
double gror = 3.0;
double lospen = 1.0;
double distster = 2.0;
boolean senpron = true;

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

crordven != 6 >= 2 && (!bamde || ri >= 5 == gror > lospen == (distster == 2)) && senpron

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"

Solution

Things to double-check in your solution:


Related puzzles: