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 tepois = 2.0;
double ru = 4.0;
double fus = 4.0;
int trengtong = 7;
int roa = 4;
int engtoip = 6;

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

tepois - ru + fus - 4 * 2 % trengtong + roa - 6 % engtoip

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double meesdang = 5.0;
double buil = 5.0;
int keall = 7;
int dradar = 7;
double ra = 3.0;
double ce = 1.0;
double re = 3.0;
int munpi = 1;
int peadass = 6;
double groughtpio = 4.0;
int elur = 3;
double he = 5.0;

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

!(meesdang < 0) != buil > keall != dradar <= ra == (ce != 7) == (re == 0) || !(munpi == peadass) || 9 >= groughtpio || elur >= he

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)

Solution

Things to double-check in your solution:


Related puzzles: