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 el = 3.0;
double bulu = 2.0;
int denthi = 2;
double ce = 2.0;
double e = 1.0;

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

2 / 2 - el % 2 * bulu % 4 + denthi / ce / e - 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean somlent = false;
boolean pri = true;
boolean tedgra = false;
int ontpre = 6;
boolean ni = false;
boolean elbe = true;
int ip = 1;
int odsus = 9;

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

somlent == (pri != tedgra || 8 >= ontpre || ni && 4 < 1) != elbe || ip <= odsus && 5 <= 7

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: