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 ehuen = 1.0;
int niojed = 3;
double angen = 4.0;
double iom = 2.0;

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

ehuen * 0 * 0 * (niojed % 8 + 5 + angen + 3 / 7) / iom

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ehic = true;
double flestsnac = 3.0;
boolean pi = true;
double lasscast = 5.0;
int iw = 8;
int ra = 7;
boolean inrond = true;
double fasthish = 5.0;
double asong = 5.0;
double dinces = 4.0;

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

ehic || 7 >= flestsnac != (pi == 8 < lasscast && iw == ra && inrond || 3 >= fasthish && asong == dinces && 7 != 0)

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: