Final Answer: $80$
General Rules
Operators which are deeper in the parse tree have higher precedence, since they are tried by the parser first.
- Left-recursive rules indicate left associativity.
- Right-recursive rules indicate right associativity.
Mapping of Operators
$\#$ corresponds to operation $*$
$\%$ corresponds to operation $\div$
Both $*$ and $\div$ are left associative, and $\div$ has higher precedence.
Given Expression
$20\#10\%5\#8\%2\%2$
Replacing operators with their actual meanings:
$\equiv 20 * (10 \div 5) * ((8 \div 2) \div 2)$
Evaluation using Precedence and Associativity
$\equiv 20 * \underbrace{(10 \div 5)}_{\text{= 2}} * \underbrace{((8 \div 2) \div 2)}_{\text{= (4 ÷ 2) = 2}}$
$\Rightarrow 20 * 2 * 2$
$\Rightarrow \underbrace{(20 * 2)}_{\text{= 40}} * 2$
$\Rightarrow 80$
Final Computed Value
$\boxed{S.val = 80}$
Hence, the value of the given expression is $80$.
Concept Summary
- Operator precedence is governed by depth in the parse tree.
- Left recursion ⟶ Left associativity
- Right recursion ⟶ Right associativity
- $\div$ binds tighter than $*$, hence evaluated first.