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 eajeng = 1.0;
double es = 5.0;
double haprir = 1.0;
double spejon = 2.0;
int pontje = 6;
int racht = 8;
double uko = 1.0;

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

eajeng * 8 * 9 * es * haprir / 7 % 1 + spejon / pontje - racht + uko

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int pijad = 4;
boolean bangang = false;
double khaeng = 2.0;
int mailad = 3;
int shedstren = 8;
int sco = 5;
boolean re = true;
int prostan = 6;
int angos = 5;
boolean lenrint = false;

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

(9 != pijad && bangang != (khaeng == mailad) != shedstren >= 8) == sco >= 4 && re != (prostan != angos) && 4 == 6 != (!(6 != 6)) == lenrint

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: