给定一些具体的语法值,我如何将它映射到不同类型的值(在本例中为 an int
)?
// Syntax
start syntax MyTree = \node: "(" MyTree left "," MyTree right ")"
| leaf: Leaf leaf
;
layout MyLayout = [\ \t\n\r]*;
lexical Leaf = [0-9]+;
不幸的是,这不起作用:
public Tree increment() {
MyTree tree = (MyTree)`(3, (1, 10))`;
return visit(tree) {
case l:(Leaf)`3` => l + 1
};
}
还是implode
进入我指定类型的 ADT 的唯一方法?