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 bropict = 4.0;
int pomer = 2;
int hicses = 9;
double irla = 1.0;

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

9 / bropict / (1 * 8 + 6 - 9 - 1 - pomer + hicses * irla) * 8 + 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int scint = 3;
int lecktro = 2;
int sastce = 4;
int touleon = 1;
double pec = 2.0;
int chissco = 7;
int minpherm = 3;
int varmen = 6;
double e = 3.0;
boolean orci = false;
boolean fa = false;
double nic = 3.0;

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

!(scint == 3) && lecktro == 3 == ((1 != sastce) && 3 >= touleon && !(pec > chissco) && minpherm > 5 || varmen <= 4 != !(5 >= e) && orci || fa != (!(nic != 4)))

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: