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 loteld = 8;
int to = 8;
int ba = 4;
int el = 5;
int andbe = 7;

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

loteld / 1 - to * ba + 7 * el - 4 / 7 % 6 - 3 - 9 * andbe

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double oanien = 2.0;
double kentiosk = 3.0;
int iafo = 9;
int gren = 3;
double prewllol = 4.0;
boolean i = true;
boolean siec = false;
int cemsu = 8;
double cror = 1.0;
boolean ol = false;

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

oanien != 7 == (2 <= kentiosk == 3 >= iafo && 1 < gren == 0 <= 3 != (prewllol != 6)) != !i == siec || cemsu != cror || ol == (!(6 != 0))

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 + 12

Solution

Things to double-check in your solution:


Related puzzles: