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 ta = 2.0;
int rhat = 3;
double pio = 4.0;
int ussscass = 7;
int lapen = 6;

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

ta % 1 * rhat % 1 - pio - 7 / 6 / ussscass / 8 - lapen

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int me = 4;
boolean esbong = false;
boolean a = false;
double or = 5.0;
int ripsal = 9;
boolean scia = false;
boolean ed = false;

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

6 == 5 == !(1 <= me) && esbong == (6 != 6) != (a || or == 4 != ripsal <= 3 == scia == !ed)

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: