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 ocen = 4.0;
double wanmurm = 2.0;
int ewi = 7;
double dre = 2.0;
double strird = 5.0;

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

6 - 4 % ocen + 5 + wanmurm - ewi * 3 % dre % strird

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ven = 8;
double sios = 3.0;
double osmma = 4.0;
int trarpa = 2;
boolean biorgoc = true;
double hapmam = 2.0;
double couss = 3.0;
int ussfri = 3;

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

ven >= 7 || (9 <= sios == osmma > trarpa || biorgoc == !(hapmam > couss) && ussfri <= 1 == (7 == 2) || !(5 != 5))

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

Solution

Things to double-check in your solution:


Related puzzles: