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 piar = 7;
double se = 1.0;
double ad = 5.0;
double noungriss = 3.0;
int ta = 9;
double dioper = 5.0;

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

piar - se / ad + 9 / noungriss - 6 % 2 * ta / dioper

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double je = 3.0;
boolean a = true;
boolean psac = true;
boolean cred = false;
double fiote = 5.0;
double soltro = 2.0;
double whobic = 4.0;

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

(3 > je || a || psac || cred || 4 < 5) && 4 < 8 || 1 < fiote && soltro >= whobic

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: