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 voss = 2;
double biciar = 1.0;
double rorstiu = 1.0;
int plar = 5;

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

(3 + 0 + voss * biciar % rorstiu / 2) + 2 * 3 * plar - 3 - 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int vi = 9;
double dokin = 4.0;
boolean piaspo = true;
boolean colast = true;
boolean en = false;
double rixpra = 5.0;
int satlon = 2;

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

vi == 3 == dokin >= 1 == piaspo == colast && 3 >= 7 && 1 != 1 && en != 2 > 6 == rixpra < 9 && satlon != 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 + 11

Solution

Things to double-check in your solution:


Related puzzles: