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 repio = 3;
int ipriacs = 7;
double grewioth = 2.0;
double otgid = 5.0;
double grirtar = 3.0;

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

repio % (7 + ipriacs) - 6 + grewioth - 2 / otgid * grirtar

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

int rirved = 5;
double phreich = 5.0;
double de = 2.0;
int raeong = 9;
double sondri = 4.0;
int ur = 2;
double qamprin = 3.0;
int e = 3;

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

rirved <= phreich || 6 != 9 == (de != raeong) || sondri > ur || 4 < 9 && 5 < 3 && qamprin != e

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

Solution

Things to double-check in your solution:


Related puzzles: