Syntax directed definations: Are a generalizations of context-free grammars in which
- Grammar symbols have an associated set of Attributes.
- Productions are associated with Semantic Rules for computing the values of attributes.
The value of an attribute of a grammar symbol at a given parse-tree node is defined by a semantic rule associated with the production used at that node.
For Example :
Let us consider the Grammar for arithmetic expressions. The Syntax Directed Definition associates to each non terminal a synthesized attribute called val.
|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|