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 esprex = 1;
double descler = 2.0;
double cao = 2.0;
double al = 2.0;
double oal = 4.0;
double boursio = 1.0;
int tranch = 2;

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

2 % (esprex - descler + cao * al - oal % 8 % boursio) * 9 / 5 % tranch - 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean pustsul = false;
boolean osssne = false;
boolean fingsast = true;
boolean etme = true;
double cansio = 2.0;
double on = 3.0;
int blaicen = 1;
double centkial = 1.0;
double niorhact = 2.0;
boolean laese = false;
int ca = 7;

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

pustsul != osssne && fingsast && (etme || cansio != on && blaicen == 4) != centkial > 2 || 5 == niorhact != 3 >= 2 && laese || 9 < ca

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: