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 guangect = 7;
double mi = 1.0;
int arseon = 9;
double ed = 3.0;
int gointo = 2;
double goungkoc = 4.0;
double o = 4.0;

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

guangect / mi - 0 - arseon - 2 % ed + gointo + 1 * 5 - 9 + goungkoc % o

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double orchjan = 4.0;
int erspla = 7;
boolean pou = true;
boolean ledstar = true;
double splues = 4.0;
boolean cri = true;
double ploro = 2.0;
boolean odiog = false;
double cin = 1.0;
int iowthmen = 7;
double lossax = 5.0;

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

orchjan < erspla && pou || 7 < 2 != (!!ledstar && 9 != splues == cri && !(9 >= 3) && 2 <= ploro) != odiog || !(2 > cin) || iowthmen >= lossax

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: