antlr4 icon indicating copy to clipboard operation
antlr4 copied to clipboard

Adding a literal token to a grammar file when it had already been defined in the lexer file - is this legal?

Open The-Futurist opened this issue 5 months ago • 3 comments
trafficstars

If I have a grammar g4 file and a lexer g4 file.

Then inadvertently insert a literal token like { into the grammar (when that same token has actually been defined in the lexer already) then is that legal or not?

I did this by mistake and it causes all sorts of weiredness in the antlr VS Code extension (which I just reported) but antlr itself doesn't complain, it process these files with that kind of change and generates .tokens files and does not report any error.

So in my lexer I had this (which I'd forgotten about):

Image

Which I'd totally forgotten about. But in my grammar g4 I simply changed this:

Image

to this

Image

then saved the change and then reran antlr and it ran fine but the antlr GUI tool does not, it gets very upset!

The-Futurist avatar Jun 06 '25 18:06 The-Futurist