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 el = 4.0;
double feieck = 4.0;
double lescousm = 1.0;
int umoe = 3;
double us = 1.0;
double vur = 5.0;
int sarqel = 4;

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

el * 9 + feieck * 4 + lescousm / 9 * umoe + us + vur % 2 * sarqel

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ausprid = true;
boolean fep = false;
double iste = 2.0;
double maeokic = 5.0;
double seposm = 2.0;
double cordes = 5.0;
boolean i = false;
boolean fuick = false;
boolean sclial = true;

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

5 <= 3 != ausprid && !fep || iste <= 2 != (maeokic != 9) || seposm < cordes || i && fuick && !sclial || 2 < 6

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: