这是例子。这个 ($type) 不能被 ANTLR4 识别。
Number //options { backtrack=true; }
: IntegerLiteral { $type = IntegerLiteral; }
| FloatLiteral { $type = FloatLiteral; }
| IntegerLiteral { $type = IntegerLiteral; }
;
这可以用什么代替?
谢谢。
最佳答案
在 ANTLR 4 中,这是新语法:
Foo
: Bar -> type(SomeType)
| ...
;
但是,对于上面的规则,您应该只删除 Number
规则并确保 FloatLiteral
和 IntegerLiteral
规则不是片段规则。
关于antlr4 - ANTLR 4 中 $type 属性的替代品是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13663525/