Tom is open source software, and the license is such that it is possible to redistribute all code generated by with no restrictions. Any user of is allowed to distribute the files generated by under the license he prefers. However, the core of the compiler itself is distributed under the GNU General Public License.
The general licensing scheme is described here.
Everything is explained in the installation guide.
Yes, the generated code and the runtime library is free. See Licensing_conditions for more details.
To make things simple, we provide a tom-runtime-full.jar
library that contains everything that could be needed. If you do not care about the size of the runtime library, just distribute your application with this library.
If you want, you can also have a finer control by selecting only the parts of the runtime library that are needed by your application:
- there are some situations where no runtime is needed, in particular when using in C mode, or when only pattern matching is used (on user defined data-structures),
- when using more advanced features, such as strategies,
tom-runtime.jar
is needed, - when using ,
aterm.jar
,jjtraveler.jar
, andshared-objects.jar
are needed, - when using syntax in ,
xercesImpl.jar
andxml-apis.jar
become needed, - when using graphical visualization of terms,
grappa1_2.jar
is needed.
The following instructions may help you to build a more tailored classpath:
(sh)
TOM_LIB_RUNTIME=`echo ${TOM_HOME}/lib/runtime/*.jar | tr ' ' ':'`
TOM_LIB_TOOLS=`echo ${TOM_HOME}/lib/tools/*.jar | tr ' ' ':'`
export CLASSPATH=.:$TOM_LIB_RUNTIME:$TOM_LIB_TOOLS:$CLASSPATH
(bash)
for i in "${TOM_HOME}"/lib/runtime/*.jar
do
TOM_LIB_RUNTIME="$TOM_LIB_RUNTIME:$i"
done
for i in "${TOM_HOME}"/lib/tools/*.jar
do
TOM_LIB_TOOLS="$TOM_LIB_TOOLS:$i"
done
export CLASSPATH=.:${TOM_LIB_TOOLS}:${TOM_LIB_TOOLS}${CLASSPATH}
(csh)
set TOM_LIB_RUNTIME=`echo ${TOM_HOME}/lib/runtime/*.jar | tr ' ' ':'`
set TOM_LIB_TOOLS=`echo ${TOM_HOME}/lib/tools/*.jar | tr ' ' ':'`
setenv CLASSPATH .:$TOM_LIB_RUNTIME:$TOM_LIB_TOOLS:$CLASSPATH
Yes, but you have to compile the compiler yourself.
You can submit a bug report on the forge, or drop a mail on the tom-users mailing list.
Yes Tom supports AC matching since the version 2.8. To use Tom AC, you have to activate it in your gom code.
We are currently designing and implementing an extension that supports subsorts. see Sorts and subsorts for more details.
In addition to the standard textual representation there is a library. Just call
tom.library.utils.Viewer.toDot(term)
(DOT representation)tom.library.utils.Viewer.toTree(term)
(tree-based ascii representation)tom.library.utils.Viewer.display(term)
(direct graphical visualization in a JFrame).
It can be used with terms and term-graphs (terms with pointers).
Yes, using the :block {}
hook.
Be sure to use a recent version of Tom such that generated creation functions are public
instead of private
.
Assume you define a strategy R()
:
import term.types.*;
class Test {
%include { term/Term.tom}
%include { sl.tom }
%strategy R() extends Fail() {
visit Term {
a() -> b()
}
}
}
If you want to use R()
in another file, you just have to create a simple mapping:
%op Strategy R() {
make() { new Test.R() }
}
Then, you can use `R()
as usual (don't forget to import sl: %include { sl.tom }
):
import term.types.*;
import tom.library.sl.*;
public class Main {
%include { term/Term.tom }
%include { sl.tom }
%op Strategy R() {
make() { new Test.R() }
}
public final static void main(String[] args) {
Term t = `a();
try {
System.out.println(`R().visit(t));
} catch(VisitFailure e) {
System.out.println("failure");
}
}
}
A solution is to pass the constant as another parameter in the %match
construct, and use non-linear patterns to check the constant.
%match(t, `Constant()) {
f(x,y), x -> { System.out.println("Constant found as first child"); }
f(x,y), y -> { System.out.println("Constant found as second child"); }
}
Which is equivalent to the following constraint-based version.
%match(t) {
f(x,y) && x << `Constant() -> { System.out.println("Constant found as first child"); }
f(x,y) && y << `Constant() -> { System.out.println("Constant found as second child"); }
}
This of course extends to java variables.
public void findName(String name, StringList l) {
%match(l) {
SList(_*,n,_*) && n << name -> { System.out.println(name + " found"); }
}
}
explain the use of functions in AU operators (%op needed to declare the function)
There exist different situations:
- you can always call a sub-strategy in the part of a construct: you just have to call
visitLight
orvisit
on another subject:
`OuterStrat.visit(t1); // or visitLight
%strategy OuterStrat() {
... -> { `InnerStrat().visit(t2); } // or visitLight
}
- if you want to apply another strategy on the current subject (and you want to maintain the position information), then you have to use the
visit
method in the following way:
`TopDown(OuterStrat).visit(t1);
%strategy OuterStrat() {
... -> {
// apply InnerStrat on t1 at the current position
`InnerStrat().visit(getEnvironment());
}
}
Since an environment is maintained, you have to apply the sub-strategy on the current environment, using visit(getEnvironment())
.
This is simple: just apply the startegy Fail()
to any object.
`Fail().visitLight(...);
- when using %gom (see Using Gom with Tom):
you have to use the
--withCongruenceStrategies
option:%gom(--withCongruenceStrategies) { ... }
- when including a mapping generated by (see Using Gom with Tom):
just add an at the beginning of the included file:
%include{ .../_term.tom }
for instance. - when generating an introspector (see Introspector): this is not possible. At present, congruence strategies can only be used when Gom is used to generate the data-structure.
- On the maximal sharing
- On the 'setters'
- On 'compareTo()'
- On 'compareToLPO()'
- On 'equivalent(shared.SharedObject obj)'
- On 'public shared.SharedObject duplicate()'
(i.e. the compiler) does not depend on the Api of generated structures (i.e. nothing is known by the compiler).
However, when generating code, also generates a mapping. This one depends and exploits the particularity of the generated code.
- It uses
==
to compare terms in constant time, thanks to maximal sharing - It does not use the 'setters'. They are generated to allow a programmer to use the data-structure directly, in a convenient way
- It does not use the 'compareTo()' nor 'compareToLPO()'. These methods are just there to help comparing terms
- It does not use 'equivalent' nor 'duplicate'. These methods are used internally, by the shared-object-factory to build terms with maximal sharing
When compiling %strategy
constructs, the data-structure is supposed to implement tom.library.sl.Visitable
.
See http://www.antlr2.org/doc/inheritance.html.
Would like to have a Java grammar (Class, Method, etc) and then to define another grammar for Struts, for example, to have ActionClass and ActionMethod. Then when matching Class to also find ActionClass.