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 spetu = 4.0;
double si = 2.0;
int trossasm = 1;
double fismen = 2.0;
int delam = 8;
double lindmin = 4.0;
double dris = 5.0;

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

4 + spetu % si + (5 % trossasm) % fismen * delam + lindmin * dris + 7 + 4

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double engkus = 2.0;
double al = 3.0;
int wetea = 5;
double prispeck = 3.0;
int a = 3;
boolean capi = false;
boolean gaber = true;
double ardack = 1.0;
double bomsism = 2.0;
double pripri = 2.0;
int giss = 9;
int chie = 4;
int pu = 5;
boolean ven = false;

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

4 < engkus != (3 != al) && (wetea >= prispeck && a < 7 == capi && !gaber) && !(ardack <= bomsism) != pripri < giss || !(chie <= pu) && ven

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: