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 prencit = 8;
double sichon = 1.0;
int droda = 1;
int laxpel = 8;
int apac = 3;
double ouwust = 1.0;
int munmi = 9;
int nesscir = 5;
int jang = 9;

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

prencit / (sichon * 1 - droda - laxpel * apac * 4 * ouwust) % munmi * nesscir % jang

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean qom = true;
boolean xensmer = false;
double pentrec = 3.0;
double briacprep = 5.0;
double flenrast = 5.0;
double anep = 4.0;
int daches = 4;

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

7 != 9 != qom != xensmer == (0 == 1) && 7 <= 8 || pentrec <= 7 && briacprep < flenrast && anep > daches && 0 >= 7 || 5 <= 5

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: