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 pe = 1.0;
double cencoul = 4.0;
int vo = 5;
int iss = 7;
int pless = 5;
double jassphliac = 1.0;

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

pe - cencoul - vo + 9 / iss + 6 + pless / 7 - jassphliac / 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int a = 5;
double denqea = 1.0;
boolean dassdi = true;
boolean restnord = false;
double fu = 5.0;
double cuntball = 3.0;
int co = 1;
double eaen = 5.0;
boolean speaecus = true;

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

a > denqea || (dassdi || restnord != (5 != fu) == (cuntball != 3) == 5 >= co) || eaen > 0 == speaecus != 0 <= 6

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

Solution

Things to double-check in your solution:


Related puzzles: