Similar questions 3 more →
Semantic Analysis & Type Checking

Answer & solution
Official answer: 80
Step through it (28 steps)
The grammar gives % higher precedence than #, with both operators left-associative. Their semantic operations are division and multiplication, respectively, rather than C remainder. The three T values are 20, 10/5=2, and (8/2)/2=2. The left-associative S combination therefore gives (20*2)*2=80. The printed nonterminal list includes an unused P, but no production or calculation depends on it.
The parse groups as (20 # (10 % 5)) # ((8 % 2) % 2). The left recursion in T fixes the latter association, so its value is (8/2)/2=2 rather than 8/(2/2)=8. S’s translation multiplies the three T values: 20×2×2=80.