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 rascrur = 9;
double shesnea = 2.0;
int pisspos = 6;
int sissces = 9;
int ol = 8;
double qi = 4.0;
double thaspecs = 4.0;

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

rascrur - 1 / shesnea + pisspos + sissces % ol * qi * 8 % 3 - 3 % thaspecs % 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double swed = 1.0;
int pholbel = 7;
boolean tedvol = false;
boolean goshbead = true;
double joght = 1.0;
int ebaess = 8;
boolean mentge = true;
boolean heous = false;

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

swed <= 4 != (3 != pholbel) && (tedvol || goshbead != (joght == 1) && 3 < 0 || 6 >= ebaess) && 2 > 1 != 0 <= 6 || mentge && heous

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 + 12)

Solution

Things to double-check in your solution:


Related puzzles: