4.1 The Structure of the Context-free Level Interface

The above mentioned patterns that are generated by the metaprogramming system, are all declared local to a specialization of the treelevel pattern. That is, the structure of the context-free level interface is:

ORIGIN '~beta/ast/astlevel'
--- astInterfaceLib: attributes ---
grammarName: treelevel
  (# ...
     (* declaration of the patterns from the grammar *)
     ...
     init::< (# do ... (* some initializations *) ... #)
  #);

Treelevel contains a local AST, grammarAST, decribing the grammar and a number of patterns (e.g. newAST, newLexemText, newConst, etc.) for instantiating new ASTs from this grammar, for identifying the version and name of the grammar, and facilities for parsing a text representation into a fragment. Finally, treelevel contains a parser attribute which can be used for parsing a text stream into an AST from the grammar in grammarAST.

The applGram fragment contains a specialization of treeLevel, called applGram. ApplGram makes the necessary setup for using the treelevel interface to any grammar.

In addition patterns are generated which provide easy creation of new ASTs from existing ones. For each nonterminal A of the grammar a generator named NewA is generated. For nonterminals defined by a constructor rule, NewA will as enter parameter take as many ASTs as there are nonterminals on the right side of the rule. It will then exit an A-AST with the enter parameters as sons


The Metaprogramming System - Reference Manual
© 1991-2002 Mjølner Informatics
[Modified: Thursday October 19th 2000 at 12:04]