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 pevec = 2;
int posmpiss = 4;
int cipeh = 7;
double propin = 5.0;
double rar = 3.0;
int ed = 7;
int il = 2;
int deu = 8;
int cout = 9;

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

pevec + posmpiss / cipeh + propin / rar + ed - il - 4 / deu - cout

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

double slishsad = 4.0;
boolean wrangsas = true;
int iant = 8;
int ect = 8;
boolean uc = true;
boolean carspiost = false;
double lu = 4.0;
boolean ne = false;
double nastel = 4.0;
int monpa = 5;

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

slishsad < 5 && (wrangsas != iant <= ect && uc || carspiost) == 1 > lu == (2 == 3) == ne && nastel >= monpa

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: