这是一个例子.ANTLR4无法识别此($ type).
Number //options { backtrack=true; }
: IntegerLiteral { $type = IntegerLiteral; }
| FloatLiteral { $type = FloatLiteral; }
| IntegerLiteral { $type = IntegerLiteral; }
;
Run Code Online (Sandbox Code Playgroud)
什么可以取而代之?
谢谢.
在ANTLR 4中,这是新语法:
Foo
: Bar -> type(SomeType)
| ...
;
Run Code Online (Sandbox Code Playgroud)
但是,对于上面的规则,您应该删除Number规则并确保FloatLiteral和IntegerLiteral规则不是片段规则.