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 tulme = 7;
double bir = 2.0;
int uidpest = 4;
double tiovung = 2.0;
int glisea = 1;

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

4 * tulme / bir % 3 - 5 % 5 % 6 % uidpest / tiovung * glisea % 3

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean chetre = true;
boolean shrildir = false;
boolean wrilk = false;
int troec = 8;
double gigean = 1.0;
boolean elhia = true;
boolean sast = true;
double mi = 1.0;
double ict = 4.0;

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

chetre || shrildir == wrilk || 3 > 3 && 3 != troec && 8 < gigean || elhia != sast != 3 > mi && ict <= 6

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: