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 antdouc = 1.0;
double varelm = 5.0;
int chress = 9;
double ced = 4.0;
double anphont = 2.0;
double phaschoss = 2.0;

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

6 % antdouc % varelm - 8 / 1 % chress * ced + 9 / 6 % anphont - phaschoss

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean chla = true;
boolean odfes = false;
double bir = 4.0;
boolean mirer = true;
double le = 3.0;
int iss = 5;
boolean stostta = false;
double slih = 4.0;
double praflac = 2.0;
boolean woscic = true;

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

chla || odfes && 8 == 9 == 9 > bir == mirer == le >= iss || 5 <= 8 && stostta && slih <= praflac || woscic

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: