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 shorod = 5.0;
double fuouc = 4.0;
int misspe = 9;
int plos = 8;
double lelsie = 1.0;

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

5 + 3 % 7 + 3 * shorod * 3 * fuouc % misspe + plos + lelsie

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ea = 9;
double plallclas = 5.0;
boolean uerbird = false;
double es = 5.0;
int veel = 2;
int dialo = 7;
int eit = 6;

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

ea == 0 && 5 >= 2 == 6 >= plallclas && !uerbird != (es == 9) == !(5 >= 9) == 2 < veel != dialo >= 4 != eit > 3

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

Solution

Things to double-check in your solution:


Related puzzles: