سؤال

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.

هل كانت مفيدة؟

المحلول 2

In ANTLR v4, do:

Number
 : IntegerLiteral {setType(IntegerLiteral);}
 | ...

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top