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 herddank = 4.0;
double thap = 3.0;
double o = 2.0;
int ea = 6;
double oi = 1.0;
int unse = 8;

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

herddank - 2 - 9 % 3 % thap * o - ea % oi + unse % 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ensueh = 7;
double musm = 1.0;
double chacal = 1.0;
int setstre = 3;
int cim = 8;
boolean schansoll = false;
int ur = 7;
double aretch = 2.0;
int shabed = 6;
boolean ple = true;

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

ensueh > musm || chacal != 7 == setstre < cim == schansoll == 0 <= ur == 7 < 5 != (aretch < 9 == (5 != shabed)) != ple

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: