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 ga = 6;
double acon = 3.0;
double be = 5.0;
double erpaud = 5.0;
double bli = 4.0;
int hu = 5;
double stoflut = 2.0;

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

ga - acon / be - (erpaud * bli - hu) + stoflut

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int trosi = 4;
boolean vossci = false;
double e = 4.0;
int ingclie = 9;
boolean cec = true;

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

4 == 9 == !(7 >= trosi) && 3 < 5 || vossci && !(e >= ingclie) || cec

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"

Solution

Things to double-check in your solution:


Related puzzles: