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 blosgrern = 3;
double blud = 5.0;
int ol = 5;
double riec = 5.0;
int cimi = 5;
int searir = 1;
double losscoings = 3.0;

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

blosgrern - blud / 6 + 4 * ol + 6 % 9 % riec % 4 % cimi - searir - losscoings

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean tir = false;
boolean beounes = true;
boolean aksour = true;
boolean allet = false;
int muwin = 6;
int ostru = 8;
boolean phasspi = true;
double gui = 3.0;
boolean ilthe = false;
boolean nossed = true;
int es = 5;
int spi = 1;

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

!tir != beounes || !!aksour != (6 == 6) || allet != (muwin >= ostru == phasspi == (1 == gui) == ilthe) || !nossed != (es != spi)

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: