Rascal 植根于术语重写。它是否具有对术语重写中通常定义的术语/节点位置的内置支持,以便我可以查询子术语在术语内的位置或以其他方式查询?
问问题
95 次
1 回答
0
我不相信在术语重写的语义中通常定义显式位置,但是尽管如此,Rascal 定义了关于术语的各种操作,使得位置是显式的或可以显式的。还请查看http://www.rascal-mpl.org上的手册
对术语的主要操作是使用普通一阶同余、深度(高阶)匹配、否定匹配、析取匹配等的模式匹配:
if (and(and(_, _), _) := and(and(true(),false()), false())) // pattern match operator :=
println("yes!");
and(true(), b) = b; // function definition, aka rewrite rule
and(false(), _) = false();
[ a | and(a,b) <- booleanList]; // comprehension with pattern as filter on a generator
innermost visit (t) { // explicit automated traversal with strategies
case and(a,b) => or(a,b)
}
b.leftHandSide = true(); // assign new child term to the leftHandSide field of the term assigned to the b variable (non-destructively, you get a new b)
b[0] = false(); // same but to the anonymous first child.
然后是正常的投影运算符,子索引term[0]
和子名称:term.myChildName
如果有许多使用字段标签定义的排序术语签名。
如果您想知道子孩子在哪个位置,我可能会这样写:
int getPos(node t, value child) = [*pre, child, *_] := getChildren(t) ? size(pre) : -1;
但还有其他方法可以实现相同的目标。
Rascal 没有指向术语的父项的指针。
于 2014-04-11T18:51:16.970 回答