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 phow = 1;
int fe = 6;
double e = 4.0;
int pla = 8;
double ro = 3.0;

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

phow - fe + 1 + e / 0 - 6 * 2 * pla % 3 * ro

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int trelldirst = 5;
int ma = 3;
boolean bodecs = true;
double crernponn = 2.0;
int mabia = 2;
boolean ori = false;
double on = 3.0;
double bedra = 3.0;
int harme = 7;
double ud = 1.0;

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

trelldirst == ma == bodecs != (5 != 4) != (5 == crernponn) == mabia < 5 && !ori && on > bedra || 1 > 8 != harme > ud

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)

Solution

Things to double-check in your solution:


Related puzzles: