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 natcha = 1;
int vante = 8;
int gecde = 6;
int ag = 5;
int psei = 9;
double flul = 5.0;
double ciore = 5.0;
double fa = 1.0;

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

7 + 7 * natcha % vante * 4 / gecde - ag * psei * flul + ciore + 1 % fa

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int fu = 1;
double scoree = 3.0;
int wreng = 6;
double ci = 1.0;
double nilos = 2.0;
boolean hectron = false;
int rubal = 5;
int pecxim = 7;
double picsto = 3.0;
double wa = 1.0;

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

(fu < scoree != (!(9 == 2)) != 9 < wreng) != (ci == 5) && nilos != 1 != 3 < 4 || !hectron != !(rubal > pecxim) && 6 == 5 != 0 >= picsto || 1 >= wa

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: