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 ris = 4;
int ge = 7;
double iglewn = 4.0;
double pu = 5.0;
double cridir = 2.0;
int hus = 5;

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

ris % ge + iglewn * 7 + 6 / 3 - 3 * pu % cridir * 4 * hus

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double sankou = 2.0;
double tradchi = 3.0;
double wor = 5.0;
double ehun = 1.0;
int ponac = 5;
double doust = 3.0;
int flagn = 1;
boolean scre = false;
boolean scroumpt = false;
boolean edia = true;
int pesqon = 5;

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

sankou <= tradchi != wor >= ehun != ponac <= doust != 6 <= flagn != scre == scroumpt != 2 >= 1 && 0 != 8 || edia || 7 < pesqon

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: