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 faeop = 4.0;
double hosm = 3.0;
double re = 2.0;
double ookrect = 3.0;
double oiiom = 5.0;
double har = 4.0;
double tibeank = 2.0;

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

(faeop / 7 - 4 % hosm / re % ookrect - oiiom - har % tibeank)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double cheph = 1.0;
boolean a = false;
int sodprik = 8;
double uior = 5.0;
int erca = 6;

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

!(5 != cheph) || a != 0 < 7 != 7 > sodprik == 8 > 4 == !(6 >= uior) == erca >= 0 && !(3 < 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

Solution

Things to double-check in your solution:


Related puzzles: