ANTLR 4中$ type属性的替换是什么?

Aft*_*ock 3 antlr4

这是一个例子.ANTLR4无法识别此($ type).

Number //options { backtrack=true; }
  :  IntegerLiteral { $type = IntegerLiteral; }
  |  FloatLiteral { $type = FloatLiteral; }
  | IntegerLiteral { $type = IntegerLiteral; }
  ;
Run Code Online (Sandbox Code Playgroud)

什么可以取而代之?

谢谢.

Sam*_*ell 5

在ANTLR 4中,这是新语法:

Foo
  : Bar -> type(SomeType)
  | ...
  ;
Run Code Online (Sandbox Code Playgroud)

但是,对于上面的规则,您应该删除Number规则并确保FloatLiteralIntegerLiteral规则不是片段规则.