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 ang = 9;
int cloo = 4;
double sephpas = 4.0;
double bi = 2.0;
double mafi = 5.0;

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

(ang + cloo / sephpas % 6 * 7 % 3 % bi / 6) % 1 + 5 - mafi

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int sesm = 9;
int siscau = 1;
int hasce = 8;
double pracsong = 1.0;
double cang = 5.0;
boolean nacsan = true;
boolean or = true;
double ec = 3.0;
int sastri = 3;
double cidbrot = 1.0;

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

0 < sesm == !(1 < siscau) != (hasce == 9) || pracsong == 1 != (cang != 6) && nacsan == 4 < 4 == or == ec < sastri == 9 >= cidbrot

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: