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 gripreng = 1.0;
int oial = 3;
int padnor = 9;
int skecrot = 6;
int acjel = 1;

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

gripreng / oial / 5 + padnor * skecrot % 1 / 9 + 3 + acjel

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double santi = 4.0;
double spinom = 1.0;
int irm = 5;
double as = 4.0;
double glucbid = 3.0;
double piochi = 5.0;
double gube = 4.0;
boolean mo = true;
boolean eoc = false;
double moaesm = 1.0;

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

(7 == santi && spinom > irm || as != 0 == !(glucbid <= piochi) != 0 > gube) == !mo || eoc && 5 <= moaesm

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"

Solution

Things to double-check in your solution:


Related puzzles: