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 re = 8;
double tiasec = 2.0;
int spo = 1;
int straa = 8;
int zessis = 2;
double sendcin = 3.0;

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

(re * tiasec + spo * straa) / zessis % 2 * sendcin + 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean vendci = true;
int benpri = 7;
int dipid = 3;
boolean drismkerk = false;
double enlasm = 4.0;
int fankqen = 5;
double soo = 2.0;

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

vendci == (!(benpri == dipid)) || (drismkerk || enlasm < 5 == 2 < fankqen) && soo < 1 || 2 == 4

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

Solution

Things to double-check in your solution:


Related puzzles: