-
Consider the syntax directed translation scheme (SDTS) given in the following. Assume attribute evaluation with bottom-up parsing, i.e., attributes are evaluated immediately after a reduction.
E → E1 * T {E.val = E1 .val * T. val}
E → T {E.val = T. val}
T → F – T1 {T.val = F.val – T1. val}
T → F {T.val = F. val}
F → 2 {F.val = 2}
F → 4 {F.val = 4}
(a) Using this SDTS, construct a parse tree for the expression 4 – 2 – 4 * 2 and also compute its E.val.
(b) It is required to compute the total number of reductions performed to parse a given input. Using synthesized attributes only, modify the SDTS given, without changing the grammar, to find E.red, the number of reductions performed while reducing an input to E.
-
- E.val = 12 ; E.red = T.red + 1
- E.val = 2 ; E.red = T.red + 1
- E.val = 10 ; E.red = T.red - 1
- All of these
Correct Option: A
(a) E.val = 12
(b) E → E1 * T {E.red = E1 .red + T. red + 1}
E → T {E.red = T.red + 1}
T → F – T1 {T.red = F.red + T1 .red + 1}
T → F {T.red = F.red + 1}
F → 2 {F.red = 1}
F → 4 {F.red = 1}