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:

int cior = 6;
double ral = 1.0;

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

3 % cior % 9 + 3 + 0 - ral % 1 - 4 + 3 - 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double stooc = 2.0;
double fri = 3.0;
double poson = 1.0;
boolean gesud = false;
double prood = 1.0;
int onsoum = 2;
double usai = 2.0;
boolean paharb = false;
boolean nomed = true;
int oc = 2;
double distio = 3.0;

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

(!(6 != stooc) != fri >= poson == !gesud == 1 > prood) == onsoum < usai && 3 > 8 == paharb || nomed && oc >= distio

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: