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 dorsir = 5.0;
int oo = 4;
int ie = 6;
double elper = 4.0;
int gi = 1;
double scantord = 3.0;

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

dorsir - oo / 3 * ie + 3 / 7 % elper / gi + 7 - scantord

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double padi = 4.0;
int tioc = 5;
double biiss = 4.0;
boolean glicoft = true;
double shausferth = 2.0;
double os = 2.0;
int ner = 8;
int i = 5;
int neschor = 1;
int di = 1;

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

padi > tioc != biiss <= 8 != (9 == 2) && glicoft || shausferth == 1 && os > 8 && !(3 >= ner) && i <= neschor != 5 >= di

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: