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 ca = 3.0;
double ejo = 1.0;
double tiac = 5.0;
double prodon = 4.0;
int qos = 3;
int cac = 3;

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

ca * ejo * 9 - tiac * prodon - qos * 4 - cac

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int stalm = 4;
int weha = 1;
double cea = 3.0;
int vomin = 3;
int io = 6;
boolean miariath = true;

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

2 <= 4 && 5 >= 1 && !(stalm >= 4) || (weha < cea != !(vomin > 0) == 4 < io) == miariath

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

Solution

Things to double-check in your solution:


Related puzzles: