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 sonti = 4.0;
int pe = 6;
int kedio = 7;
int arleuc = 4;
int lanass = 9;
double sirvod = 1.0;
int candur = 6;
int thess = 2;

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

sonti + (pe / kedio * 7 / arleuc - lanass - sirvod) % candur % 2 - thess

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int astar = 2;
double rer = 3.0;
int haindel = 5;
boolean o = false;
boolean ciant = false;
double ollman = 3.0;
boolean si = true;
int trengan = 8;
int phe = 6;
boolean mousdouc = false;

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

!(astar < rer) || 3 > haindel != o == !ciant && 1 >= 9 == (ollman != 8) != si && !(trengan < phe) != mousdouc

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: