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 previn = 1.0;
int pirce = 3;
double linhor = 4.0;
double slidprel = 4.0;
int fronot = 1;
double as = 2.0;
int asswer = 1;
int buip = 5;

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

previn + 6 - pirce * linhor + slidprel * 1 * fronot / as % 2 * 6 % asswer + buip

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ple = 5.0;
boolean slerdmoi = false;
boolean viober = false;
boolean bagaet = false;
int grigie = 8;
double pi = 5.0;
boolean al = false;
int troorec = 4;
int tilasm = 3;

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

5 < 9 && !(2 >= 5) != ple > 7 != slerdmoi || viober && !bagaet == (4 != grigie) || 3 >= pi && al != (5 != troorec) || 4 == tilasm

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) + 12

Solution

Things to double-check in your solution:


Related puzzles: