複数の面倒な割り当てなしで次のコードを書くにはどうすればよいですか?
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.
};