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 lo = 4.0;
double songstreo = 2.0;
int cicksme = 5;
double phusmud = 3.0;
int hentqi = 5;
int ongruast = 1;
double pepal = 2.0;

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

7 % lo + songstreo * 7 * cicksme + phusmud * 7 * 0 % hentqi * 1 % ongruast + pepal

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean mimant = true;
double siothec = 5.0;
double nilib = 5.0;
boolean ris = true;
int thibel = 3;
boolean glan = false;
int cesmno = 3;
int traon = 5;
int duex = 4;
double moonkproo = 3.0;
boolean poc = true;
boolean ecpearn = true;

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

mimant != (8 == siothec) || nilib <= 6 != !ris && thibel == 3 == glan || cesmno >= traon || !(duex <= moonkproo) == poc != 6 < 7 == !ecpearn

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: