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 zista = 3.0;
int shermind = 4;
double us = 1.0;
double besmden = 5.0;
double gebel = 4.0;

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

zista * 5 * 6 + (shermind % 5) / us % 2 * 0 / besmden * 9 - gebel

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double rhidlunt = 4.0;
boolean sase = false;
double prallsith = 2.0;
int seast = 6;
int il = 5;
double ki = 2.0;
int teoutchvun = 4;
double cangtron = 1.0;
boolean gran = true;
boolean muouwo = false;
double cec = 4.0;

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

7 != rhidlunt != sase && prallsith > seast || il > ki || 8 >= teoutchvun != cangtron >= 7 != (!(9 == 2)) != gran != muouwo && cec == 5

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)

Solution

Things to double-check in your solution:


Related puzzles: