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 sas = 1;
double mec = 2.0;
double ha = 4.0;
int screlist = 1;
int ris = 9;
double besptrent = 3.0;

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

sas / mec + ha + screlist / ris / besptrent - 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int peu = 1;
double heoruc = 2.0;
boolean teazeel = false;
double on = 2.0;
double frirhesm = 3.0;
int curspont = 4;
double nui = 4.0;
double re = 5.0;
boolean gacec = true;

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

peu < heoruc == teazeel != !(on > 0) != (frirhesm == curspont) == nui > re || gacec

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

Solution

Things to double-check in your solution:


Related puzzles: