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 ik = 1.0;
int craism = 9;
int clulco = 7;
double bleast = 1.0;
double indir = 5.0;
int bloddid = 6;

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

ik * (craism % 7 - 8 + clulco / bleast + indir - 1) - 9 % 1 % bloddid - 6

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean lidsio = true;
boolean ma = false;
double simgrio = 2.0;
boolean durmte = true;
boolean pilmus = false;
int piaaunt = 5;
boolean spenmea = true;
int tacel = 2;
int twueci = 1;
int coard = 3;
boolean cacpoa = false;

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

lidsio != ma != simgrio <= 7 && durmte == pilmus || 1 > piaaunt != 2 <= 3 != spenmea && 3 >= tacel && twueci != coard || cacpoa

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: