public final class TRS<V> extends Object implements TreeRewriter<V>, Serializable
final TRS<String> trs = TRS.parse(
"add(0,$x) -> $x",
"add(S($x),$y) -> S(add($x,$y))",
"mul(0,$x) -> 0",
"mul(S($x),$y) -> add(mul($x,$y),$y)"
);
// Converting the input tree into its normal form.
final TreeNode<String> tree = TreeNode.parse("add(S(0),S(mul(S(0),S(S(0)))))");
trs.rewrite(tree);
assert tree.equals(TreeNode.parse("S(S(S(S(0))))"));TreeRewriteRule,
TRS,
Serialized Form| Constructor and Description |
|---|
TRS(ISeq<TreeRewriteRule<V>> rules)
Create a new TRS from the given rewrite rules.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object obj) |
int |
hashCode() |
<B> TRS<B> |
map(Function<? super V,? extends B> mapper)
Maps
this TRS from type V to type B. |
static <V> TRS<V> |
parse(Function<? super String,? extends V> mapper,
String... rules)
Create a new TRS from the given rewrite rules and type mapper.
|
static TRS<String> |
parse(String... rules)
Create a new TRS from the given rewrite rules.
|
int |
rewrite(TreeNode<V> tree,
int limit)
Applies the rewriting to the given (mutable)
tree. |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitconcat, rewrite, rewrite, rewritepublic TRS(ISeq<TreeRewriteRule<V>> rules)
rules - the rewrite rules the TRS consists ofNullPointerException - if the given rules are nullIllegalArgumentException - if the given rules sequence is
emptypublic int rewrite(TreeNode<V> tree, int limit)
TreeRewritertree. The tree
rewrite is done in place. Via the limit parameter, the termination
of the tree-rewrite process can be guaranteed.rewrite in interface TreeRewriter<V>tree - the tree to be rewrittenlimit - the maximal number this rewrite rule is applied to the given
tree. This guarantees the termination of the rewrite method.treepublic <B> TRS<B> map(Function<? super V,? extends B> mapper)
this TRS from type V to type B.B - the target typemapper - the type mapperNullPointerException - if the mapper is nullpublic static <V> TRS<V> parse(Function<? super String,? extends V> mapper, String... rules)
V - the tree value type the rewriter is working onmapper - the tree value type mapperrules - the rewrite rulesNullPointerException - if one of the arguments is nullIllegalArgumentException - if the given rules sequence is
emptypublic static TRS<String> parse(String... rules)
rules - the rewrite rulesNullPointerException - if one of the arguments is nullIllegalArgumentException - if the given rules sequence is
empty© 2007-2019 Franz Wilhelmstötter (2019-11-18 20:30)