Understanding ANTLR's mysterious error messages.

Monty Zukowski

> ANTLR Parser Generator   Version 2.7.1a4   1989-2000 jGuru.com
> error: Token stream error reading
> grammar(s):antlr.TokenStreamRecognitionException: unexpected char:
> TokenStreamException: unexpected char: ?
The first message is about a newline, which is just printed as a newline. The second one is about a question mark, probably, or possibly an unprintable character.
> How do i pinpoint the source of this...
Well, it's really annoying when you get this kind of error from antlr. First thing to do is double check all of your semicolons--make sure you end every rule with one. Second, make sure all of you braces, brackets, quotes and parens balance. Third, start a new file and copy rules in just a few at a time until you get the error. Yes, I've had to do this.

Fourth, to prevent such problems in the future, use RCS or perforce or some other commandline version control system. CHECK IN WITH EVERY COMPILE. I'm serious. Make it part of your build process. You really have to be able to "undo" your last or last few changes since the working version. Not only because of the unusable error message above, but also because you will end up making a mistake in your grammar that screws everything up and hunting those down is really tough.