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 innant = 9;
double mapho = 4.0;
int odxen = 4;
int sa = 6;

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

innant * 4 / mapho / 9 - 6 / 1 - odxen * 7 - sa

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean gerba = false;
double rol = 3.0;
int honeng = 3;
double ve = 4.0;
int glinor = 7;
int ranttiac = 7;
double u = 5.0;
double ivench = 5.0;
boolean in = true;
int ophsost = 7;
boolean rer = true;

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

gerba && rol < honeng || !(3 <= ve) && glinor > ranttiac == u > ivench && in && 8 > ophsost != rer

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

Solution

Things to double-check in your solution:


Related puzzles: