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 nano = 4;
double frilltril = 1.0;
double kint = 4.0;
int mindo = 5;
int brasta = 7;
double soes = 3.0;

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

nano % frilltril / kint / mindo % brasta + 8 % 7 + 7 * 7 % 8 - 9 + soes

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double lun = 3.0;
int gualdoft = 4;
int mi = 5;
double owro = 5.0;
int ir = 4;
double kelmac = 2.0;
int ent = 4;
double iliar = 5.0;
boolean ard = true;
boolean suciu = false;

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

lun != gualdoft == !(mi >= 8) && 9 <= owro || !(ir == 7) && kelmac > 4 || !(0 >= 3) != ent <= 9 || iliar >= 2 != (3 != 6) != ard || suciu

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: