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 rastse = 2.0;
double al = 3.0;
int dast = 6;

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

6 * (6 - rastse - 6 * al) / 4 - 4 / 2 * dast + 0

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double be = 2.0;
int as = 9;
int qess = 6;
double e = 5.0;
double zio = 5.0;
int hissbid = 5;
boolean meing = false;
boolean si = true;
int norio = 6;
int bluss = 2;
double becciss = 2.0;
double spration = 1.0;
int pidix = 7;
int phifreng = 7;
double haguss = 2.0;

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

be == as && qess >= e && zio != hissbid != meing == (si || norio <= bluss) && becciss < spration && 2 < pidix || phifreng <= haguss

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: