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 trelfla = 8;
int a = 1;
double prabal = 3.0;
double giriast = 2.0;
double vi = 2.0;
double priosshin = 2.0;
int pingal = 5;
int cadir = 5;

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

trelfla / 4 - (a + prabal + giriast % 2 / vi) - priosshin - 4 + pingal % cadir

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double dulert = 5.0;
boolean rossur = false;
boolean i = false;
boolean e = false;
int diax = 6;
double od = 2.0;
boolean maging = false;

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

dulert == 6 && !!rossur != i || !e != 8 >= 1 != !(1 <= 5) != (7 != 6) || diax >= 9 || 5 >= od != maging

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 + 11

Solution

Things to double-check in your solution:


Related puzzles: