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 mebru = 2.0;
double usspel = 3.0;
double a = 1.0;
int wa = 5;
int co = 4;
double o = 3.0;
int gossthal = 7;
int scros = 7;

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

mebru - 9 - usspel * a - wa + co / o + gossthal + scros

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double hirtre = 2.0;
boolean spinsest = true;
int tre = 2;
boolean cer = false;
boolean scosproch = true;
boolean pras = false;
int hiad = 6;
int ro = 6;

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

hirtre == 1 != spinsest && tre >= 5 || cer == !scosproch && 1 <= 4 || pras || hiad == ro

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: