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 astoss = 5.0;
double tristsphest = 2.0;
double te = 4.0;
double pha = 2.0;
int phate = 8;
double cisad = 4.0;

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

7 + 9 / astoss / 1 / 5 - 4 / tristsphest * (te * pha % 7 % phate) + cisad

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean frel = false;
boolean pra = false;
int diass = 4;
boolean nicis = true;
int madbin = 5;
int ficfrun = 2;
double pordo = 2.0;
double hi = 1.0;
double de = 5.0;
int splassel = 4;
int aighpi = 5;
double i = 2.0;
int hil = 4;

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

frel == pra && 5 != diass != nicis == madbin > 9 || ficfrun <= 0 || !(4 < pordo) || hi <= de && 8 != 8 || splassel > aighpi || i < hil

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" + 12

Solution

Things to double-check in your solution:


Related puzzles: