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 ress = 9;
double tradko = 2.0;
double surhe = 1.0;
int e = 7;
int la = 4;
double pilrhal = 3.0;

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

7 + 9 + 6 * ress / tradko + (surhe + e / la - pilrhal - 0)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean leic = true;
double bingcuck = 3.0;
boolean mirtspi = true;
double chisblo = 1.0;
int iong = 4;
double i = 2.0;
double banel = 2.0;
double in = 5.0;
boolean esspi = false;

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

leic || bingcuck == 0 != mirtspi == 3 <= chisblo && iong < i != (5 == 4) && 3 <= 0 || banel >= in == esspi

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: