Syntax-Directed Definitions


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.
An attribute grammar is an SDD without side effects, which are modifications of a non-local environment such as printing a value.
The following SDD (attribute grammar) evaluates arithmetic expressions with operators + and * terminated by an endmarker n. For example, the expression “3 * 5 + 4 n” is evaluated to 19.

In the SDD, each of the nonterminals has a single attribute, called Val. Explanations of some productions are
  Production Semantic Rules
1. <L> ::= <E> n Val(<L>) = Val(<E>)
2. <E> ::= <E1> + <T> Val(<E>) = Val(<E1>) + Val(<T>)
3. <E> ::= <T> Val(<E>) = Val(<T>)
4. <T> ::= <T1> * <F> Val(<T>) = Val(<T1>) × Val(<F>)
5. <T> ::= <F> Val(<T>) = Val(<F>)
6. <F> ::= ( <E> ) Val(<F>) = Val(<E>)
7. <F> ::= digit Val(<F>) = Lexval(digit)