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 chesspo = 4.0;
double nen = 3.0;
int eci = 9;
double whircho = 1.0;
int dacour = 4;
int brertbon = 1;
int eja = 7;

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

8 + chesspo % 1 - nen / eci * whircho - 7 / 3 / dacour + brertbon % eja

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean hous = true;
int pephi = 2;
double il = 4.0;
int la = 8;
int bewo = 8;
double skec = 5.0;
int euts = 1;
boolean jool = true;
int prisnal = 5;
double ci = 1.0;
double acial = 2.0;
int prae = 8;
boolean o = false;

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

!hous != (pephi >= 5 == 3 <= il == la < bewo || skec <= euts && !jool == (!(8 != prisnal)) == ci >= acial) || !(9 <= prae) || o

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: