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 eazzpes = 2;
double ro = 3.0;
int oreip = 9;
double krort = 5.0;
int masset = 9;
double dedoct = 2.0;

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

eazzpes * ro / 5 % 2 - oreip + 9 * krort % 7 % 8 + masset % 3 * dedoct

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ost = 5.0;
int da = 1;
double bunnos = 3.0;
boolean i = false;
boolean minvin = false;
double mior = 4.0;
double tio = 1.0;
double loi = 5.0;
int or = 6;
int vastuic = 5;
double prianoc = 3.0;
int eul = 8;
int cioter = 2;
double preng = 4.0;

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

ost == da || 4 >= 5 == (!(0 == bunnos)) == i != !minvin && mior < tio == ((loi == or) == vastuic >= 9 == prianoc < eul) != (5 == cioter) == preng < 8

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: