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 fips = 2.0;
double sange = 3.0;
double punhor = 5.0;
double i = 4.0;
double resm = 3.0;
double eo = 1.0;

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

1 + fips - sange - 6 + 6 * punhor + i - resm - eo + 3 / 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean pisca = false;
double suad = 4.0;
double daprus = 4.0;
int el = 2;
double prer = 2.0;
double qel = 1.0;
int il = 5;
int so = 9;
int en = 6;

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

!pisca != !(3 >= 7) == suad > daprus || !(0 != el) == (7 != 3) != (6 != 8) && prer < qel || 5 <= 4 && il == 1 && so == en

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: