Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the replacement for $type attribute in ANTLR 4?

Tags:

antlr4

Here is the example. This ($type) is not recognised by ANTLR4.

Number //options { backtrack=true; }
  :  IntegerLiteral { $type = IntegerLiteral; }
  |  FloatLiteral { $type = FloatLiteral; }
  | IntegerLiteral { $type = IntegerLiteral; }
  ;

What could this be replaced by?

Thank you.

like image 387
Aftershock Avatar asked Nov 28 '25 22:11

Aftershock


1 Answers

In ANTLR 4, this is the new syntax:

Foo
  : Bar -> type(SomeType)
  | ...
  ;

However, for the rule you have above you should just remove the Number rule and make sure the FloatLiteral and IntegerLiteral rules are not fragment rules.

like image 160
Sam Harwell Avatar answered Dec 02 '25 03:12

Sam Harwell