Compiler Design: SDTS, LR Parsing, and Code Optimization
Syntax-Directed Translation Schemes (SDTS)
A possible Syntax-Directed Translation Scheme (SDTS) uses the attribute val to store the value of each non-terminal.
- E → E1 + T { E.val = E1.val + T.val }
- E → T { E.val = T.val }
- T → T1 * F { T.val = T1.val * F.val }
- T → F { T.val = F.val }
- F → num { F.val = num.value }
Bottom-Up Evaluation of 3 + 2 * 4
Evaluation using SDTS (bottom-up):
- F → num(4): F.val = 4
- F → num(2): F.val = 2
- F → num(3): F.val = 3
- T → F (for num(2)): T.val = F.val = 2
- T → T * F: T.val = T.val (from num(2)) * F.val (from num(4)) = 2 * 4 = 8
- T → F (for num(3)): T.val = F.val = 3
- E → T (for num(3)): E.val = T.val = 3
- E → E + T: E.val = E.val (from num(3)) + T.val (from 2 * 4) = 3 + 8 = 11
Therefore, the result of the computation... Continue reading "Compiler Design: SDTS, LR Parsing, and Code Optimization" »
English with a size of 232.62 KB