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 he = 4.0;
int sno = 8;
double cesni = 2.0;
double so = 1.0;
int sanphiss = 9;
int gutvus = 1;
int clalder = 7;

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

he * 6 % sno * cesni % so / sanphiss * 0 / gutvus / 6 * clalder % 9 - 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int soi = 8;
int dore = 8;
int siel = 1;
boolean ir = false;
boolean roki = true;
boolean brirspith = false;
boolean crosac = true;
boolean cerod = true;
int prence = 1;
double thict = 2.0;
boolean hik = true;
double whass = 1.0;

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

!(8 <= soi) == 6 <= dore != (3 < siel || ir != roki != brirspith) || !crosac != cerod != prence <= thict || hik || whass >= 4

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 + 12

Solution

Things to double-check in your solution:


Related puzzles: