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 pses = 4.0;
double unpas = 3.0;
double psan = 5.0;
double cieaed = 3.0;
double al = 2.0;

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

pses - unpas * 6 - 3 / 1 - psan % cieaed % 9 / 3 * 7 + 8 + al

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean mesle = true;
boolean morcad = true;
double flirdpri = 5.0;
int ur = 2;
boolean loat = true;
double hadrex = 5.0;
boolean cricild = true;
boolean qongdas = true;
boolean ro = true;
int peuix = 1;
double doschan = 4.0;
double a = 5.0;

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

mesle || morcad && flirdpri <= ur == loat == 8 > hadrex != cricild == qongdas && ro == peuix >= doschan == 4 < 6 == 8 > a

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" + 12)

Solution

Things to double-check in your solution:


Related puzzles: