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 uned = 2.0;
double scerd = 5.0;
int dus = 8;
double oc = 4.0;
int sesmsu = 6;

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

(2 % uned / 7 / 6 % scerd * dus - oc) % 7 / 1 + sesmsu

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean idspess = false;
int sentroc = 3;
double trosh = 1.0;
double cint = 4.0;
double os = 2.0;
int ciis = 9;
int scri = 4;
double codpal = 2.0;

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

7 <= 1 != !idspess && sentroc >= 5 || (6 >= 1 == !(trosh > 4) || 6 <= cint) && !(4 >= os) != (ciis == 4) && scri < codpal

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: