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 pe = 5;
int lehod = 2;
double maor = 1.0;
double ri = 3.0;
int leeda = 8;
double cuxser = 4.0;
double cirtsong = 4.0;
int chepo = 7;
int e = 6;

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

pe * 5 / lehod % 9 / maor * ri + leeda / cuxser / cirtsong % 9 / chepo + e

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int prar = 7;
int enk = 6;
int ie = 5;
double ridklent = 5.0;
int hibi = 6;
boolean a = true;
int sistspli = 2;
boolean ci = true;
int moadspen = 2;
double buru = 3.0;
double le = 2.0;
int prioluc = 5;
double ossnal = 2.0;

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

!(!(0 < prar)) != enk <= ie || ridklent == hibi && !(9 != 4) == a && sistspli > 7 != ci != 2 <= moadspen != (buru != 8) == !(le > prioluc) || ossnal >= 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 + 12

Solution

Things to double-check in your solution:


Related puzzles: