[antlr-interest] Exception on obscure char but then continue lexing?

Martin Olsson mnemo at minimum.se
Mon Aug 1 02:33:11 PDT 2005


Hi,

I'm using an ANTLR parser to detect syntax errors in a c-like language.
Currently if the lexer runs into for instance the char "¤" (which is not a
part of my language) it will throw a NoViableAltForCharException which is
then wrapped into a TokenStreamRecognitionException. I catch this and
display the syntax error in my editor.

The problem is that ANTLR seems to stop parsing too at this time. Instead
I would like it to throw an exception as above, but then just ignore that
character and resume lexing more or less as if the erroneous char never
appeared (it should also, if possible, start over with flushed buffer so
that the chars "func¤tion" will not be interpretted as a valid "function"
token.

Is this possible with ANTLR 2.7.5 ? Are there any examples of this?



Sincerly,
Martin


More information about the antlr-interest mailing list