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 rosson = 3.0;
int prile = 9;
int blorsti = 8;
double gric = 5.0;
int lemoc = 1;

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

(6 / 6 / rosson + 4 - prile + blorsti + gric % 5) + 5 - 8 * lemoc

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double pe = 4.0;
int pentcer = 4;
int ecmiss = 9;
int groi = 1;
double sas = 1.0;
double anthbe = 5.0;
double tred = 3.0;
boolean meshad = false;
int orpa = 9;
double spo = 1.0;
int moasm = 9;
int ar = 9;
int uczirk = 3;
double sercoan = 3.0;
int erent = 2;
boolean iaud = true;

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

pe >= pentcer == ecmiss >= groi || !(5 <= sas) || anthbe != tred && meshad != (orpa <= 5 && spo >= moasm != ar > uczirk != (!(sercoan != erent)) || iaud)

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: