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 sostcess = 8;
double iasba = 4.0;
int rangim = 4;
double thrier = 2.0;
int co = 1;
int proam = 7;
int riscen = 9;

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

sostcess % (1 - iasba % 8 + rangim - thrier * co % 3 + 3) - proam - 7 / riscen

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean bu = false;
int eck = 6;
int proph = 5;
int oodlosh = 4;
boolean it = false;
double re = 2.0;
double macet = 3.0;
int pel = 9;
boolean rasswac = true;
double il = 4.0;
int napra = 1;
double mo = 3.0;

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

bu != 1 > 6 == (7 != eck) == proph >= oodlosh == it != (re == 6) == !(macet > 3) != 5 >= pel == rasswac || 5 != il != (napra != mo)

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: