| A factory of factories. This tool reads in a factory declaration,
which contains one or more snippets of literal Java or C code and
then creates the corresponding Java factory class. The class has
one method per snippet, with each method instantiating the abstract
syntax tree representing the code snippet. Code snippets may be:
- Declarations,
- Statements,
- Expressions.
Code snippets may also contain pattern variables:
# Name represents a single value, to be
supplied when instantiating the pattern.
#[ Name] represents a list of
values, also to be supplied when instantiating the pattern.
For each pattern variable, the corresponding method has a parameter
of the same name; the actual argument supplies the correponding
value(s) when instantiating the pattern. Single-valued pattern
variables may appear instead of:
- Declarations or statements in blocks,
- Types or identifiers in variable declarations,
- Expressions.
List-valued pattern variables may appear instead of:
- Declarations or statements in blocks,
- Arguments to a function or method call.
Consider this example factory description containing C
snippets:
alias number;
factory xtc.lang.Stuff {
declare { number * #name ; }
block { { int i; double d; #[statements] } }
add { #number + 5 }
call { #function ( #[arguments] ) }
}
The optional alias declaration may only appear in factory
declarations with C snippets; it lists all typedef names used in
the C snippets as a comma-separate list. In the example,
"number " is a typedef name. It is followed by the
factory declaration itself, whose name, here
"xtc.lang.Stuff ", is the fully qualified name of the
generated Java class. The body of the factory declaration consists
of one or more method declarations, with each method declaration
consisting of a method name followed by the Java or C snippet
enclodes in curley braces. The example declares four methods:
declare creates a variable declaration of some
name being a pointer to number .
block creates a compound statement with variable
declarations for i and d and some list of
statements.
add creates an additive expression that adds
some expression number to the integer 5.
call creates a function call of some
function on some list of arguments.
The recommended file extension for factory declarations with
Java snippets is ".ffj " and with C snippets
".ffc ".
author: Robert Grimm version: $Revision: 1.16 $ |