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 edro = 4.0;
int to = 2;
int uc = 9;
double slis = 5.0;
double hi = 3.0;
double trasssa = 2.0;
int pineaert = 5;

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

edro + to * 9 * (uc - 0 + 5 % slis - hi / trasssa / pineaert)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ia = true;
boolean ijid = false;
int erid = 6;
int na = 6;
double ousmded = 5.0;
int eant = 4;
boolean an = false;
boolean dainush = false;
int ruda = 2;

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

ia != ijid != erid >= 5 && !(!(4 == na)) == 2 < 1 == ousmded >= eant && !an && dainush != ruda > 8

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: