The metaprogramming system also contains an interface to the
Fragment System of the Mjølner BETA System. The fragment
system enables the management and manipulation of ASTs located on different files. The functionality of the fragment system allows the splitting of an AST into an number of sub-ASTs (sub-trees) by allowing some interior nodes in the original AST to be replaced by special nodes, called slotDesc. The AST, originally positioned at the position of that node, may by located on a totally different file (possibly along with other sub-ASTs). All these ASTs are called fragments. Fragments are named in an hierarchical name space, similar to the UNIX hierarchical file system. The full name of a fragment has the following structure: /name1/name2/.../namen/frag, where /name1/name2/.../namen is called the path of the fragments and frag is called the local name of the fragment. The path of a fragment is the same as the full name of the father of the fragment. Fragments are usually located in files on the file system. Fragments are stored in two different formats: textual representation and binary representation. The binary representation is considered the essential representation of fragments, and the purpose of the textual representation is human reading, printing or parsing into the binary representation. If the fragment is created using tools based on the metaprogramming system, there is no reason for storing the textual representation since the binary representation contains all necessary information.
The fragment system interface of the metaprogramming system is used as the basis for the fragment system for BETA [MIA 90-2].
The fragment system interface consists essentially of four major patterns:
- Fragment is an abstract pattern for the three other patterns, implementing the following operations: Name accesses the local name of the fragment and fullName accesses the full name of the fragment. DiskFilename refers to the name of the file containing the binary representation, and textFilename refers to the file containing the textual representation. Father returns a reference to the father of this fragment, and type refers to the fragment type (group, form, or link). Init initializes the fragment, reset resets the fragment as if it has just been parsed from the textual representation, and close closes the fragment. ModTime returns the time for the last change to this fragment, changed indicates whether this fragment has been changed, markAsChanged sets the changed mark, and checkDiskRepresentation will check if the disk representation has been changed. Fragments may have properties associated with them. These properties are kept in the prop attribute, which is a list of properties, where each property carries one value. In a subsequent section, properties are discussed in more detail.
- Fragment also contains a few operations, related to the BETA specific fragment system: Origin refers to the origin of the BETA fragmens, bind binds a fragment within this BETA fragment and bindToOrigin binds this fragment to its origin.
- FragmentForm represents one single (sub-)AST. It contains the following operations: Category refering to the syntactic category of the root node of the AST in this fragmentForm. Print makes an almost readable dump of the fragmentForm. Root refers to the AST of this fragmentForm, grammar refers to the grammar, describing the grammar of the language of this fragmentForm, and scanSlots iterates through all slots in this fragmentForm. Finally, the BETA specific attribute binding refers to the slot to which this fragmentForm have been bound.
- FragmentGroup represents a group of (sub-)ASTs. FragmentList is the list, containing all the fragments in this group. Open makes it possible to get access to a single fragment in the group, scan makes it possible to iterate through all the fragments of this group, and parse makes it possible to parse a file into a fragment group. DefaultGrammar refers to the grammar used for this fragmentGroup. SetupOrigin, getBinding and getBETAbindings can be used for accessing the slot bindings.
- FragmentLink represents a link to some other fragment (e.g. the INCLUDE link in the BETA fragment system). It contains a reference to the fragment, and the various names for that link.
The fragment system interface also influences the AST interface a few places. First of all, an AST has a frag attribute, which refers to the fragment containing this AST. Secondly, unExpanded has the attributes isSlot and theSlot, where isSlot is true if this node in the AST represents a slot, and theSlot contains information (name and syntactic category) on the slot. Slots is inserted in the AST in the following way:
(# aSlot: ^slotDesc; anUnexpanded: ^unExpanded;
do ... -> newUnExpanded -> anUnexpanded;
newSlot -> aSlot;
'foo' -> aSlot.name;
aSlot -> theUnexpanded.theSlot
|The Metaprogramming System - Reference Manual
||© 1991-2004 Mjølner Informatics
[Modified: Friday April 6th 2001 at 12:43]