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 acdrad = 1.0;
int swesphial = 8;
int coi = 3;
int a = 4;
double hu = 3.0;
double asprong = 1.0;
double phasstes = 1.0;

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

0 / (acdrad / 8 * 1 % swesphial / coi) / a * hu / asprong * phasstes

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean lunex = false;
boolean whoc = true;
int ahnien = 9;
int pontmi = 9;
boolean phe = true;
double occhosm = 2.0;
double blaud = 5.0;
boolean echa = false;
double pri = 1.0;

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

lunex == whoc && (ahnien < pontmi != !phe == 8 >= occhosm) != !(!(6 >= blaud)) != (8 == 3) != echa == 5 > pri

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: