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 er = 1;
double posssier = 1.0;
double cel = 2.0;
double caud = 1.0;
double fio = 3.0;
int glelbiun = 5;
double fastan = 1.0;

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

er * (1 / 9 % posssier) - cel % caud + fio + glelbiun * fastan

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean soung = true;
int hi = 5;
int be = 7;
boolean scutuss = false;
boolean farur = false;
int mallal = 9;
double miacha = 3.0;

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

soung && hi <= be || scutuss != farur && 6 != mallal && 0 < miacha && 0 < 9 && 3 > 1

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: