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 ha = 1.0;
int staxclist = 2;
double ecfa = 2.0;
int phoost = 9;
double bamic = 5.0;
int or = 8;

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

4 + 6 % 1 - ha % staxclist * ecfa * phoost * 8 - bamic % or / 3 % 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean sconlam = false;
boolean escul = true;
int ranto = 4;
boolean goim = false;
double ca = 5.0;
boolean rau = false;
double ac = 4.0;
int dro = 7;
int pashep = 2;

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

(!sconlam && escul != !(ranto < 1)) && goim == 9 > ca || rau == 4 <= 4 == (6 == 9) == 2 <= ac != dro >= 3 == 8 <= pashep

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: