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 tism = 7;
double a = 3.0;
int edel = 7;
double ma = 1.0;
double bu = 2.0;
int rasu = 1;

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

tism - 2 * (a - edel % ma * bu % 5) * rasu

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean prefrep = false;
int precress = 8;
double knahed = 2.0;
double chua = 5.0;
double cestgearm = 4.0;
int prosuff = 8;
int i = 7;

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

prefrep && precress < 2 && knahed >= chua == 4 > 8 == (5 != 1) || cestgearm < prosuff || 4 <= i

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"

Solution

Things to double-check in your solution:


Related puzzles: