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 an = 5.0;
double onvar = 3.0;
double plirsa = 3.0;
int ces = 5;
int sorcunt = 7;
int armtil = 5;
int mi = 1;

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

an + 6 * 5 % onvar / 5 + plirsa / 4 * ces - sorcunt - armtil / mi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean obo = true;
double spep = 2.0;
boolean esschal = false;
double ni = 5.0;
boolean poc = false;
boolean io = false;
boolean padung = true;
double carmson = 4.0;
int peo = 6;

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

obo != (9 <= spep != esschal == (2 == 1)) || 7 <= ni != poc && io || !padung || 7 < carmson != peo > 1

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: