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
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top