next up previous contents index
Next: Storage Options Up: Input Previous: Defining Terms

   
Attributes of Terms

Phyla can be declared to have attributes   of a predeclared type. This type can be any C type, e.g. int, or float. Of course, it can also be a C type that is generated by Kimwitu. An example phylum with attributes is:  


expr: Plus(expr expr) | Minus(expr expr) | Neg(expr) | Zero() { float value = 0;} ;
Here the attribute value of type float is defined, and initialised with 0.   Multiple attributes can be defined between the curly brackets. The initialisations are optional. The type of an attribute can also be a type generated by the term processor (such as a phylum).

Attributes serve as a facility to decorate a tree with extra information. The decoration can be done in arbitrary user code. The attribute becomes a component of the record that is generated for the phylum. If x is a value of type expr, then the attribute can be referred to as x $\rightarrow$value.

As the last item of the initialisation a piece of arbitrary C, enclosed in curly brackets, is allowed. In this code the expression $0 denotes the term that is being created. The code is executed after the term has been built completely, and the other initialisations have been performed. An alternative way of expressing the above initialisation therefore is:


{ float value; { $0->value=0;}}


next up previous contents index
Next: Storage Options Up: Input Previous: Defining Terms

2000-04-17