Is there way to have some code both in lexer and parser members in combined grammar?

StackOverflow https://stackoverflow.com/questions/20481550

  •  30-08-2022
  •  | 
  •  

I have a utility method which I use in both lexer and parser -generated code in a combined grammar. Other than moving it to an external utility class, is there some way to get rid of copy/paste to members and lexer::members, and have this method emitted both in generated Lexer, and Parser?

I am using Antlr 3... I guess if there's something new that is added in 4 that would also be useful information.

有帮助吗?

解决方案

No, it is placed in either the parser, or the lexer (both for v3 and v4). If possible, you could, of course, make it static so that it's easily called from both.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top