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 bightah = 1.0;
int huack = 6;
double bulirn = 5.0;
double stidte = 2.0;
double ga = 2.0;
int vinrar = 1;
double iiass = 2.0;
double ec = 1.0;

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

(bightah % 9 * huack + bulirn * stidte) / 1 % ga - vinrar / iiass + ec

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ses = 5.0;
int thia = 2;
double grebra = 5.0;
boolean he = false;
double ol = 1.0;
int oshas = 3;
double lanta = 2.0;
int e = 1;
boolean debla = false;
boolean cirfu = true;
boolean rek = true;

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

ses != 5 && thia > grebra && he || ol < oshas && (lanta == e != debla || cirfu == rek) == 0 < 8

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: