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 lasm = 5;
double gagre = 2.0;
int marceu = 1;
int nafra = 5;
double ses = 5.0;
int hisherm = 8;

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

6 / 4 * lasm / (gagre * 8 * marceu / nafra * 4 / 7) + ses * hisherm - 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean trecsdo = true;
boolean e = true;
double mec = 5.0;
double buine = 3.0;
int prial = 4;
boolean hapeic = false;
double strer = 3.0;
double es = 4.0;
int craspus = 3;
double lal = 2.0;
int rhengban = 6;
double rar = 5.0;
double vouh = 2.0;
double seff = 1.0;
double in = 4.0;

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

(trecsdo == e && mec < buine == 3 <= prial != hapeic == (3 == strer)) && es > 3 == (craspus != lal) || rhengban == rar == vouh < 3 || seff < in

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: