In: Computer Science
Given a Syntax Directed Translation as follows.
Production |
Semantic Rules |
L → E n |
L.val = E.val |
E → E1 + T |
E.val = E1 .val + T.val |
E → T |
E.val =T.val |
T → T1 * F |
T.val = T1.val x F.val |
T → F |
T.val = F.val |
F → ( E ) |
F.val = E.val |
F → digit |
F.val = digit.lexval |
Question
Create an annotated parse tree for the following statements
An annotated parse tree contains the values of attributes at each node for given input string. There are two types of attributes in an annotated parse tree.
1. Synthesized attributes and
2. Inherited attributes.
In an annotated parse tree value of synthesized attribute at node is computed from the values of attributes at children nodes in parse tree. In the first and second examples we used synthesized attributes.
The value of inherited attributes are computed by value of parent or sibling nodes.