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 si = 3.0;
double teac = 5.0;
double o = 3.0;
double nostscui = 3.0;
double sosrem = 5.0;

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

8 - si + 6 + teac / o / 8 * nostscui - 0 * 0 + 6 / sosrem

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ca = 5.0;
int gi = 4;
double e = 2.0;
double ceon = 2.0;
boolean craten = false;
int ia = 5;
int trehesh = 6;
double rihus = 1.0;
int stri = 2;
double sirdlo = 4.0;
double anha = 2.0;
int triiold = 9;
int fu = 4;

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

ca != gi == e < ceon != !craten || ia < trehesh == 8 <= 9 || !(rihus <= 2) && stri <= sirdlo && anha > 4 != triiold <= 8 && !(1 <= fu)

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: