abstract syntax

Phyla (terms) can be defined in the following way (you can see a phylum as a non-terminal, and an Operator as a name that identies a production rule):

phylum: Operator( sub-phyla ) | ... ;

(we borrowed this syntax to define phyla from SSL (the Synthesizer Specification Language that is the input language of the Synthesizer Generator, a system to generate language-based editors))

The abstract syntax for our language can defined as follows:


expr: Const( int ) /* int is predefined */ | Plus( expr expr ) | Times( expr expr ) ;
We expect here only non-negative int values, if needed we can check for this. Note that parentheses are implied by the form (structure) of the tree -- with the Operator we can distinguish between the rule for the plus (+) and the times (*) operators.

Phyla can have attributes, as we will see later.

expression creation

Of the above input kimwitu generates data type (struct) definitions (each phylum is mapped onto a C type with the same name), and create functions (each operator is mapped onto a C function with the same name). We can use the generated create functions to construct a term (tree). To construct a term for: (1 + 1) * (1 + 1) we can write:

expr e = Times( Plus( Const( 1 ), Const( 1 )), Plus( Const( 1 ), Const( 1 )) );

next overview up


Last updated at 03 February '98 by kimwitu@cs.utwente.nl