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 lopri = 7;
double o = 5.0;
int iar = 9;
double liovi = 3.0;
double crosin = 3.0;
double fisi = 4.0;

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

lopri * o - iar % liovi / crosin * 8 + 5 - 3 / fisi * 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double ra = 5.0;
int ea = 5;
double dengbe = 3.0;
double mio = 5.0;
double ba = 4.0;
double cessgunt = 4.0;
boolean dolp = false;
boolean peckond = false;
int id = 2;

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

ra >= 0 && ea <= dengbe && mio > 0 == 5 <= ba && 4 >= cessgunt == dolp == 8 <= 4 != peckond == id > 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: