Compiler Design and Construction - Old Questions
5. Define Syntax directed definition. Construct annotated parse tree for the input expression (5*3+2)*5 according to the following syntax directed definition.
Production |
Semantic
Rule |
L
-> En |
Print
E.val |
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
-> (E) |
F.val
-> (E.val) |
F
-> digit |
F.val
-> digit.lexval |
A syntax-directed definition (SDD) is a context-free grammar together with attributes and rules. Attributes are associated with grammar symbols and rules are associated with productions. For example,
Production
|
Semantic
Rules |
E → E1 + T |
E.val
= E1.val+T.val |
E → T |
E.val
= T.val |
The annotated parse tree for the input expression (5*3+2)*5 using given syntax directed definition is shown below: