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 piimpt = 1;
double qen = 1.0;
double beswe = 4.0;
double scin = 1.0;
int ang = 8;

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

piimpt / 6 * 6 + qen + 2 - beswe + scin % ang * 8

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double lackpre = 5.0;
double io = 3.0;
boolean esmess = true;
int mic = 1;
boolean sescliar = false;
double chermmett = 2.0;
int zouss = 4;
double glirned = 4.0;
double eseac = 5.0;

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

!(6 >= 0) != lackpre < io || esmess == 1 > mic != sescliar != chermmett >= zouss == (glirned != eseac) || 7 <= 8

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: