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 nascrock = 4.0;
int puent = 7;
double hentgin = 2.0;
int balthiod = 3;
double bledcont = 1.0;
int osa = 8;
int fladit = 5;

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

nascrock * (8 + 4 - puent) % 1 * hentgin % balthiod * 0 / bledcont % osa - fladit

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean esos = true;
boolean tre = false;
int kesmsec = 2;
boolean reebcoll = false;
double cin = 5.0;
int as = 1;
double tingos = 5.0;
boolean kio = true;
int e = 2;
int preocpil = 8;

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

esos && tre && (!(8 >= kesmsec) == reebcoll && !(cin >= as) && 5 <= tingos || kio != (!(1 != e)) == 2 < 9 != !(preocpil < 7))

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: