Multiple choice

Consider the grammar with the following translation rules and E as the start symbol. E ® E1 # T {E.value = E1.value * T.value} | T {E.value = T.value } T ® T1 & F {T.value = T1.value + F.value} | F {T.value = F.value} F ® num {F.value = num.value } Compute E. value for the root of the parse tree for the expression: 2 # 3 & 5 # 6 & 4.

  1. 200

  2. 180

  3. 160

  4. 40

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The expression is 2 # 3 & 5 # 6 & 4. Following the rules: E -> E1 # T (E1 * T) and T -> T1 & F (T1 + F). The expression evaluates as (2 # (3 & 5)) # (6 & 4). 3 & 5 = 8. 2 # 8 = 16. 6 & 4 = 10. 16 # 10 = 160.