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:

double ori = 4.0;
int phou = 7;
double mo = 2.0;
int humo = 5;
int oon = 2;
int psanre = 9;

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

ori + phou + mo - 2 / 9 - humo + (oon - psanre)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double hul = 1.0;
double pao = 2.0;
int cechdir = 1;
double sepheu = 5.0;
boolean depos = false;
double peunchos = 1.0;
double rass = 4.0;

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

(hul < pao && !(cechdir != 5) || !(sepheu > 8) || depos && 6 >= 0 || 1 <= peunchos || rass <= 9)

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: