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 od = 3;
double bletha = 3.0;
double eschiss = 5.0;
double ro = 5.0;
double reai = 5.0;
double ip = 3.0;

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

od * 1 / 3 % (1 + 9) / bletha % eschiss - ro % reai - ip

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int ifoa = 1;
double braphe = 3.0;
int ca = 3;
int iel = 9;
double sothpa = 1.0;
boolean blidmis = true;
boolean casmcun = false;
double enghal = 4.0;
boolean setria = true;
double opris = 4.0;
double ochru = 4.0;

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

ifoa < braphe || ca > 3 && iel >= sothpa || blidmis || casmcun || (2 <= enghal != setria || 3 >= 7) || opris >= ochru

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

Solution

Things to double-check in your solution:


Related puzzles: