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 seng = 3;
int co = 3;
double lec = 1.0;

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

7 - 3 * seng / 5 - co * 9 + 2 * 1 * 2 + lec

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double wopar = 5.0;
boolean i = false;
double dros = 1.0;
int ussfer = 8;
int grou = 9;
double bedic = 2.0;
int mees = 5;
int fispu = 8;
double sanhu = 4.0;
boolean ploc = true;

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

wopar == 8 && 1 <= 2 || i != dros > ussfer || 4 >= grou != 4 <= bedic && mees < 1 || fispu < sanhu == ploc

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: