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 rineer = 7;
double go = 2.0;
double sasew = 2.0;
double stripdio = 4.0;
double ed = 5.0;
int drila = 2;
double ma = 5.0;
double prasmscint = 5.0;

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

6 + rineer / go + sasew + stripdio + 2 - ed / drila % ma / prasmscint + 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double lesne = 5.0;
double oso = 4.0;
int fouptwol = 1;
boolean biouth = false;
boolean rer = true;
double jal = 3.0;
boolean sestpriass = true;
double elmang = 1.0;
double cirgops = 2.0;

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

lesne != oso && 3 < fouptwol != biouth && (rer == jal <= 4 != sestpriass != (3 != 7)) && !(8 <= 8) != 6 <= elmang && !(6 <= cirgops)

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: