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 ceed = 3.0;
double sler = 3.0;
double mecze = 4.0;
double ni = 3.0;
double pel = 4.0;
int tiis = 7;

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

9 % ceed / 7 + sler % mecze + 1 + 3 + ni % pel - tiis * 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int wiossen = 3;
int enbae = 3;
double phlaf = 5.0;
boolean na = false;
boolean dunfor = false;
int daor = 1;
int dircost = 5;
boolean alcoc = false;
int ma = 3;
int iendtant = 1;
double poordgres = 5.0;

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

5 >= wiossen && 2 == enbae == phlaf <= 8 || (na != dunfor && daor < 6 == dircost >= 2 && alcoc) != ma < iendtant || 6 > poordgres

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: