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 nir = 5.0;
double natser = 1.0;
int hotsal = 4;
double drera = 2.0;
int poumo = 3;
double hesa = 2.0;
int chaonproc = 8;

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

nir * 1 - natser * 5 % hotsal * drera + poumo % hesa * (3 / chaonproc - 9)

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int mulslel = 3;
boolean spesil = true;
boolean ciac = true;
int tesri = 5;
double i = 5.0;
double ildod = 2.0;
double hu = 2.0;
double pi = 4.0;
boolean seca = true;
boolean alna = false;
int prosdi = 9;
boolean blopen = true;

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

3 <= mulslel && spesil == ciac != tesri < i || !(ildod < hu) && pi != 6 || seca || alna == (!(prosdi == 2)) != !blopen

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: