# Documentation:Term-Graph Rewriting

(Difference between revisions)
 Revision as of 12:16, 15 May 2009 (view source)m ← Previous diff Current revision (12:45, 21 March 2013) (view source) (add comment about dot (mandatory program)) Line 5: Line 5: terms are implemented with maximal sharing, so are the term-graphs. Term-graphs terms are implemented with maximal sharing, so are the term-graphs. Term-graphs can be specified using label constructors. can be specified using label constructors. + + {{note |  This example needs dot program, which is a part of Graphviz. It is mandatory to install it to make the Viewer run properly.}}

## Current revision

 Doc : Guided Tour Algebraic terms  > Hooks  > Mappings  > Graphs  > Subtyping

Using the Gom option `--termgraph`, it is possible to automatically generate from a signature the extended version for term-graphs. As the Tom terms are implemented with maximal sharing, so are the term-graphs. Term-graphs can be specified using label constructors.

 Note: This example needs dot program, which is a part of Graphviz. It is mandatory to install it to make the Viewer run properly.
```import testlist.m.types.*;
import testlist.m.*;
import tom.library.sl.*;
import tom.library.utils.Viewer;

public class TestList {

%include{sl.tom}

%gom(--termgraph) {
module m
abstract syntax

Term = a()
| b()
| c()
| d()

| nil()
| insert(element:Term,list:List)

sort List: graphrules(Insert,Identity) {
}
}

public static void main(String[] args) {

List abcd = (List)
LabList("2",insert(b(),
System.out.println("Original subject");
Viewer.display(abcd);
System.out.println("Insertion with term-graph rules from Gom");
try {
Viewer.display(`TopDown(List.Insert()).visit(abcd));
} catch(VisitFailure e) {
System.out.println("Unexcepted failure!");
}
}

}```

Users can define a system of term-graph rules and it is automatically compiled in a basic Tom strategy. These term-graph rewriting rules can then be integrated in a more complex strategy using Tom strategy combinators. As a consequence, all Tom features are available for term-graphs.

 Guided Tour Algebraic terms  > Hooks  > Mappings  > Graphs  > Subtyping Tom Documentation Guided Tour :: Tutorial :: Language Reference :: Tools