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 inti = 7;
double diswad = 1.0;

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

5 - 0 - inti - 3 + 7 / 8 / diswad % 1

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double tobolt = 5.0;
double wecmun = 2.0;
boolean conont = false;
boolean iss = false;
double krep = 5.0;
double sucdost = 3.0;
double roboc = 3.0;

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

4 > 7 != tobolt > wecmun && !conont != iss && 0 >= 1 || krep != 8 && sucdost <= roboc

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

Solution

Things to double-check in your solution:


Related puzzles: