parse tree
parse tree
Sanchez
Analysis:
1. 2 ** 3 ** 2
Right-sided binding (exponentiation operator).
Evaluated as 2 ** (3 ** 2) = 2 ** 9 = 512.
2. 10 / 2 * 3
Left-sided binding.
Evaluated as (10 / 2) * 3 = 5 * 3 = 15.
3. 5 + 3 - 2
Left-sided binding.
Evaluated as (5 + 3) - 2 = 8 - 2 = 6.
4. 8 % 3 * 2
Left-sided binding.
Evaluated as (8 % 3) * 2 = 2 * 2 = 4.
5. -4 ** 2
Right-sided binding (unary operator binds more strongly).
Evaluated as -(4 ** 2) = -16.
Parse Trees:
1. Expression: 2 ** 3 ** 2 4. Expression: 8 % 3 * 2
**
/ \ *
2 ** /\
/ \ % 2
3 2 /\
2. Expression: 10 / 2 * 3
8 3
*
/ \
/ 3 5. Expression: - 4 ** 2
/
-
/
\
10 2
**
3. Expression: 5 + 3 - 2
/ \
-
4 2
/\
+ 2
/\
5 3