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 to = 3;
int besou = 1;
int cidphi = 5;
double ruciou = 3.0;
double dism = 4.0;
int et = 8;
int throlceng = 3;
int pimcoun = 6;

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

to / 9 + 9 + besou * cidphi % ruciou / dism % (8 / et - 4 - throlceng) % pimcoun

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean cak = true;
boolean as = false;
boolean dossgle = true;
int an = 1;
double ralphmer = 5.0;
boolean fofloi = true;
double pa = 3.0;
int di = 7;
double esent = 5.0;
double herchrerd = 2.0;

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

(cak && !(5 >= 9) != as && dossgle) == (4 != an) || ralphmer >= 1 || fofloi || pa > 0 || di != 4 == !(esent <= herchrerd) != 2 >= 9

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: