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 anuen = 1;
double sossu = 4.0;
int souwo = 4;
double peethrist = 2.0;
int ebad = 7;
int ainpel = 8;
double e = 3.0;
double pozi = 4.0;

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

anuen - (5 - sossu - souwo / peethrist % 2 - ebad + ainpel % e) / pozi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double muop = 2.0;
int tes = 6;
double wou = 2.0;
int angoc = 3;
double lissned = 4.0;
boolean ar = false;
int so = 2;
int sehel = 5;
boolean flosm = false;
boolean ol = false;

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

!(muop >= 7) && tes == wou || 8 != 0 == (angoc != lissned) == ar == so < sehel != (2 == 7) || flosm == ol

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: