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 scheeo = 7;
double ceahass = 4.0;
double ca = 2.0;
int eper = 7;

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

2 / scheeo % ceahass / 9 % 4 + ca * 1 * 7 - 0 - 1 / eper / 9

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean o = true;
double fismess = 3.0;
int aber = 2;
int pasas = 9;
double fralve = 1.0;
double tu = 5.0;
int od = 7;
double tostrad = 4.0;
boolean slict = false;
int necad = 4;
boolean sqioxoff = false;

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

o || !(4 > 2) == (9 >= fismess && aber != 4 == (!(1 == pasas))) == (fralve == tu) || !(!(od <= tostrad)) == slict != necad >= 7 && 3 < 3 || sqioxoff

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 + "12"

Solution

Things to double-check in your solution:


Related puzzles: