如何在没有多个繁琐的分配的情况下编写以下代码?
statement returns [Leaf node]
: assignment {node = $assignment.node;}
| write {node = $write.node;}
| writeln {node = $writeln.node;}
| readBool {node = $readBool.node;}
| readInt {node = $readInt.node;}
;
像下面这样的东西就足够了。
statement returns [Leaf node]
: a=(assignment | write | writeln | ...) { //all statements returns `Leaf`
node = $a.node; //but 'a' is just a `Tokien`, so we get compile error.
};