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 gric = 2;
int prisoft = 7;
double nosmer = 2.0;
double u = 5.0;
int prilu = 6;
int ropreoud = 6;

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

1 / gric - prisoft - 8 - 9 + nosmer - 2 - u % prilu - ropreoud - 2

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int xeuss = 7;
boolean vui = false;
boolean scealen = false;
double au = 1.0;
int bre = 8;
double phrecspe = 3.0;
int tia = 8;
double el = 5.0;
double gni = 2.0;
int mencu = 5;
double e = 3.0;
double id = 2.0;

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

7 >= xeuss && vui == scealen && 2 != 2 || (6 > 2 && au > bre == 3 <= phrecspe == tia <= el && gni == mencu && e >= id)

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: