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 cernu = 5.0;
double cer = 3.0;
int el = 2;
double reada = 5.0;
double cichi = 4.0;
int hipirt = 1;
double virrel = 1.0;
double oss = 2.0;

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

4 + 7 % cernu / cer - el + reada - 3 + cichi + hipirt * 2 - virrel % oss

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int albre = 1;
int jiou = 2;
double dassant = 2.0;
boolean horui = false;
double miom = 3.0;
double fli = 5.0;
double rhostion = 2.0;
boolean spesm = true;
double fi = 2.0;
boolean ploird = false;
double ir = 1.0;

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

!(3 < albre) == jiou < dassant == horui || miom == fli == (rhostion == 5) && 2 <= 8 && !spesm || 7 == fi && ploird == (ir != 1) || !(!(3 == 2))

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: