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 triwit = 6;
double picish = 5.0;
int siacan = 8;
int doepmas = 2;
int tosmje = 1;
int ul = 6;

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

9 % triwit + 3 * picish - 7 % 3 + 8 - siacan - doepmas * tosmje % ul / 5

Solution

Things to double-check in your solution:


Part 2

Given the following variables:

boolean messtad = false;
boolean an = true;
boolean pousm = false;
double prili = 5.0;
double hinfre = 4.0;
double istthien = 4.0;
int ehes = 6;
int ced = 3;
double ong = 1.0;
double brolfol = 1.0;
int ramsa = 5;
double issu = 3.0;
boolean rileng = true;
boolean eceo = true;

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

messtad != !an && pousm || prili <= hinfre || istthien >= ehes || !(4 == ced) || ong <= brolfol != ramsa <= 1 == (!(4 == issu)) && rileng || !eceo

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: