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:

int li = 8;
double butresm = 2.0;
double pe = 3.0;
int hootess = 2;
double nopin = 1.0;

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

2 * li / butresm - pe * 1 * 1 * hootess + 3 + nopin + 7

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int on = 1;
int pra = 4;
double nic = 4.0;
double tasteae = 4.0;
int sas = 2;
boolean ek = false;

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

on != 4 == pra > 1 != (!(5 <= 3) == nic <= 8 || tasteae == sas) || ek != !(8 >= 9) == 2 >= 4 != (!(2 != 3))

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: