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 to = 4;
int soo = 6;
int niopcront = 8;
double pe = 2.0;
int henvos = 7;
int ichi = 3;

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

9 % to / 3 + 0 / soo * niopcront / 4 % 7 / pe % henvos - ichi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean glasmaw = false;
double hesm = 3.0;
double pel = 4.0;
int splekord = 2;
double stredesm = 4.0;
double doncir = 1.0;
double beirn = 1.0;
boolean bapoa = false;
boolean mi = true;

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

glasmaw && hesm > pel != splekord >= 4 || 2 < 4 || 5 < stredesm || doncir != 8 != beirn >= 5 != bapoa && 1 <= 1 != !mi

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)

Solution

Things to double-check in your solution:


Related puzzles: