1
給定一些具體的語法值,我如何將它映射到不同類型的值(在這種情況下是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?