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 crausma = 4.0;
int hil = 9;
int altkach = 2;
double boi = 4.0;
double ec = 2.0;
double viedil = 2.0;
double a = 1.0;
double eltru = 3.0;
int sengsel = 7;

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

crausma * hil + altkach - 1 * boi * ec % 7 - viedil + a / eltru * sengsel

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double vilaec = 2.0;
int garlheouc = 2;
double kre = 4.0;
boolean veco = false;
int me = 1;
boolean codpught = false;
boolean wrodrai = false;
int ucsrint = 9;
double dinvang = 3.0;
double hecbrund = 4.0;
int qud = 9;
int eru = 2;
boolean feim = false;

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

9 >= vilaec == garlheouc <= kre || veco == me < 0 == codpught || wrodrai != ucsrint >= dinvang || hecbrund >= 8 && qud != eru && feim

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: