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 glirion = 1.0;
int si = 6;
double fien = 2.0;
int bu = 3;
double fashni = 1.0;

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

0 * glirion + si / fien - 7 - 1 / 7 / bu + fashni

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ral = 2.0;
double o = 2.0;
int etan = 4;
int estti = 2;
int sosmant = 3;
double efes = 3.0;
double otpe = 1.0;
boolean cahoa = false;
boolean phramol = true;

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

ral > o != (etan >= estti == !(7 <= sosmant)) && 3 != 3 != !(6 >= 0) != efes >= otpe || cahoa || phramol

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: