8.1 Predefined mappings
8.1.1 Builtin sorts
The system comes with several predefined
signature-mappings for C, Java and Caml.
Among them, let us mention:
-
boolean.tom (true or false)
- char.tom (written 'a', 'b', etc.)
- double.tom (using Java grammar for double)
- float.tom (using Java grammar for float)
- int.tom (written 1, 2, 3, etc.)
- long.tom (written 1l or 1L, etc.)
- string.tom (written "a", "ab", etc.)
These mappings define, for each builtin sort of the host language, an
algebraic sort that can be used in a %match or a signature
definition construct.
Thus, builtin values, such as f(5), g('a') or
h("foo"), can be used in patterns.
The string.tom mapping is interesting because it provides an
associative operator (concString) which allows the programmer
to consider a string as a list of characters.
Thus, the string "foo" can be seen as the algebraic object
concString('f','o','o').
By using this mapping, it becomes possible to perform pattern matching
against the content of a string.
The pattern concString('f',X*) will match any string which
begins with the character 'f'.
By using the unnamed-symbol capability, this pattern can be written:
('f',X*) instead of concString('f',X*).
To match any string which begins with the substring "fo", the
corresponding pattern should be ('f','o',X*).
To simplify the definitions of such patterns, Tom supports an
exception which allows the programmer to write ('fo',X*)
instead. Internally, the ill-formed character 'fo' is expanded
into the list ('f','o'). Thus, the annotated notation
y@'fo' is expanded into (y@'f',y@'o'), and thus may be
dangerous to use in this case.
In addition to these mappings, several other predefined mappings come
with the system:
-
aterm.tom and atermlist.tom provide a mapping to
the C and Java version of the ATerm Library
- caml/list.tom provides a mapping to the builtin notion of List
in Caml
- java/dom.tom provides a mapping to the Java version of the
DOM Library
8.1.2 Java
To help manipulating Java data-structures, Tom provides several mappings
for the Java Runtime Library. The naming convention follows Java's one:
java
o--- Character.tom
+--- util
o--- ArrayList.tom
o--- HashMap.tom
o--- HashSet.tom
o--- LinkedList.tom
o--- MapEntry.tom
o--- TreeMap.tom
o--- TreeSet.tom
+--- types
o--- AbsractCollection.tom
o--- AbsractList.tom
o--- AbsractSequentialList.tom
o--- AbsractSet.tom
o--- ArrayList.tom
o--- Collection.tom
o--- HashMap.tom
o--- HashSet.tom
o--- LinkedHashSet.tom
o--- Map.tom
o--- Object.tom
o--- Stack.tom
o--- TreeMap.tom
o--- TreeSet.tom
o--- Vector.tom
o--- WeakHashMap.tom
The directory types contains only %typeterm declarations.
8.1.3 Strategies
To support strategies, Tom provides a predefined mapping to allow the
description of strategies.
-
mustrategy.tom: maps the basic strategies classes, and provides a
mu operator to express the recursion as well a MuVar(v:String)
operator to allow the definition of complex strategies as described in
Section 7.3.
8.1.4 Bytecode
To support the analysis and transformation of Java bytecode programs, Tom
provides several mappings and libraries:
-
adt/bytecode/Bytecode.tom provides an abstract syntax tree
implementation to represent any Java bytecode program. In addition, a Gom
library is also provided
- adt/bytecode/_Bytecode.tom contains the congruence strategies
associated to the AST
- java/bytecode/cfg.tom defines new strategies that allows to
explore the control flow graph.
To support the transformation of Xml documents, Tom provides a
specific syntax for defining patterns, as well as several predefined
mappings:
-
dom.tom: maps Xml notation to a Java implementation of the DOM library
- dom_1.5.tom: maps Xml notation to a Java (version 1.5)
implementation of the DOM library
- TNode.tom: maps Xml notation to an ATerm based representation,
generated by Gom
See Section 5.4 for a detailed description of the Xml
facilities offered by Tom.