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 qioff = 4;
double eterr = 2.0;
int spir = 4;
double ingser = 1.0;
double venglo = 2.0;
double alphod = 4.0;

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

qioff * (eterr % spir - ingser % 9 * 7) + 0 * venglo / alphod

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double bemleeng = 3.0;
int eour = 5;
int badbec = 9;
double radi = 2.0;
double vidtron = 1.0;
double moudes = 1.0;
double eckmess = 1.0;
boolean xon = true;
double tuasa = 5.0;
double spu = 1.0;
double e = 2.0;
double co = 5.0;

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

3 <= bemleeng || !(4 == 1) == eour < badbec && radi == vidtron && moudes <= eckmess == !xon && tuasa <= spu && !(e <= co)

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"

Solution

Things to double-check in your solution:


Related puzzles: