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 flapes = 5.0;
double rir = 2.0;
double tinglel = 1.0;
double mespad = 4.0;
int perar = 3;
int a = 3;
double seans = 2.0;
int uqa = 4;

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

flapes / 7 + 5 + 1 % rir % 2 + tinglel - mespad * perar / a / seans % uqa

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double gliilum = 2.0;
int e = 6;
double ciocshec = 1.0;
double ranhe = 1.0;
boolean ungnen = true;
int o = 9;
boolean lus = true;
double ris = 1.0;
boolean shasmad = false;
boolean peces = true;
boolean oc = true;

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

0 > gliilum || 3 < e != (!(ciocshec != 3)) != (ranhe != 3) || ungnen && o <= 1 || lus && ris >= 3 && shasmad && peces == oc

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: