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 mo = 9;
int parsan = 3;
double tresm = 4.0;
double ochit = 4.0;
double bosson = 2.0;

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

mo * (parsan * 1 / tresm - 6) % ochit / 5 + 6 % bosson % 4 % 5 * 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double re = 1.0;
int je = 7;
int paceng = 8;
double ded = 1.0;
double phri = 5.0;
int colste = 3;
double ar = 3.0;
boolean sa = false;
boolean laeo = true;
boolean schengdoc = false;
double on = 5.0;

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

5 > 1 || re == je && 9 > paceng || 6 <= ded == (phri != 6) == colste >= ar || sa || (3 != 6 != laeo) != schengdoc == (!(4 == on))

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: