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 pesm = 4.0;
int to = 3;
int muiss = 7;
double pto = 5.0;
double neso = 4.0;
int razeod = 7;
int ued = 9;
int sheuk = 5;

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

4 * pesm * to / muiss + pto * neso % razeod / ued / (4 / sheuk * 5)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double decve = 2.0;
int orme = 8;
boolean scu = false;
int crafleu = 4;
double gesio = 1.0;
boolean ia = true;
int vios = 5;
double khoc = 4.0;
double mioprird = 4.0;
boolean tous = false;

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

!(6 != 7) == 7 < decve == !(!(orme <= 6)) != scu == (crafleu != gesio) == ia != (4 != vios) == 4 < 0 || khoc != mioprird == tous

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: