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 glac = 5.0;
double vidpras = 4.0;
double es = 5.0;

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

4 * 1 - (6 - glac - 1 - vidpras - es - 9) / 5 % 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int sciep = 1;
double ai = 5.0;
int on = 2;
double hunrasm = 2.0;
double leldimn = 4.0;
boolean ongpem = true;
boolean le = true;
double pussfo = 3.0;
boolean essor = true;
double ecpheng = 4.0;
double sode = 1.0;

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

sciep <= ai || on <= hunrasm || 3 < leldimn || ongpem && 4 <= 6 && le != pussfo >= 4 == !essor || ecpheng < sode

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

Solution

Things to double-check in your solution:


Related puzzles: