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 a = 5.0;
double pradu = 5.0;
double en = 1.0;
int ma = 6;
int dai = 4;
int saclal = 8;
int docno = 9;

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

a % 4 + 5 / 2 + 6 * pradu * en * ma / dai + saclal + docno

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int o = 6;
int eptspo = 5;
int husshid = 9;
int cer = 4;
double pabel = 2.0;
boolean ee = false;
boolean croismsir = true;
int er = 1;
int hisnint = 3;
double ti = 4.0;

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

o == 4 && !(eptspo > 9) || (8 > husshid != cer >= pabel == !ee != 9 < 1 || croismsir) == er < 4 && hisnint >= 3 != ti <= 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

Solution

Things to double-check in your solution:


Related puzzles: