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 trushec = 5;
double prifro = 3.0;
double coint = 1.0;
int tarph = 1;

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

trushec + prifro / coint % 5 - 8 / 1 * 3 / 9 + 7 + 7 * tarph

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ontia = true;
double deng = 5.0;
double rotot = 5.0;
double olplesm = 5.0;
double knoirist = 1.0;
boolean firseng = false;
int necuh = 1;
int coddo = 5;
double hu = 3.0;
double repnat = 5.0;

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

!ontia && 7 >= 5 || 8 != 4 && !(deng <= rotot) == (!(6 < 6) && olplesm < 0 || knoirist != 2) && firseng || necuh > coddo || hu > repnat

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" + 11

Solution

Things to double-check in your solution:


Related puzzles: