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 scri = 6;
double berd = 1.0;
double streecmo = 5.0;
double traspla = 2.0;

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

9 * 9 / scri + berd * 2 / 2 * streecmo * traspla / 9 / 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int meirp = 5;
boolean nedpeus = true;
int wor = 7;
double hous = 3.0;
int idi = 3;
boolean imfrer = true;
int riar = 5;
int murna = 8;
int sartra = 1;
int trie = 1;

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

6 >= meirp == nedpeus == (wor < 0 == 4 <= 8) && hous < idi == imfrer || !(3 != riar) == murna > sartra == 0 < trie

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

Solution

Things to double-check in your solution:


Related puzzles: