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 chiche = 3.0;
int squnphint = 7;
double puu = 3.0;
int fengsai = 9;
double ca = 1.0;
int coplel = 5;
double i = 2.0;
double spissme = 2.0;

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

chiche / 4 + 0 * squnphint % puu + fengsai - ca * coplel + i % spissme * 4 + 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean ang = true;
double lerelf = 4.0;
int in = 2;
boolean nestmon = false;
double pioing = 4.0;
double beshlel = 1.0;
boolean chessin = true;
int lami = 6;
int es = 3;
double pher = 1.0;
double jicuph = 4.0;
double sudshre = 1.0;

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

ang && 3 != lerelf || !(6 != in) && nestmon != (5 == pioing) && (!(beshlel > 7) || chessin || lami != es != pher >= jicuph || sudshre == 1) != 8 > 6

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: