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 samic = 8;
int preuit = 1;
int mi = 8;
double hepwhi = 2.0;
int e = 5;
int naru = 1;

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

samic * 6 + preuit / mi - hepwhi * 6 / e / 7 % 3 + naru

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int eghtpri = 8;
int sodsa = 5;
boolean predscrid = true;
boolean proxwi = true;
double fe = 5.0;
boolean et = false;
double opkne = 4.0;
double enbel = 2.0;
boolean uentcess = true;
boolean qiem = true;

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

eghtpri != 5 && 9 < sodsa == predscrid == (proxwi == fe >= 2 && et == (opkne != enbel) == uentcess) && qiem

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: