[antlr-interest] c++ libantlr: panic()

Ross Bencina rbencina at iprimus.com.au
Wed Mar 19 15:02:39 PST 2003


I notice that the warning/error message handling seems to have been improved
since last time I played with antlr - with virtual reportError() and
reportWarning() functions that can be overridden. This is really good.

There may be an issue with panic() though:

CharScanner.hpp, line 321:
/// Called when a unrecoverable error is encountered
 void panic();
 /// Called when a unrecoverable error is encountered
 void panic(const ANTLR_USE_NAMESPACE(std)string& s);

Parser.hpp, line 167:
static void panic();

TreeParser.hpp, line 65:
/// Give panic message and exit the program. can be overridden in subclass
static void panic();


So panic() is currently declared as static in two of three base classes. One
of these says "can be overridden in subclass" which is not possible for a
non-virtual function.

May I suggest that panic be changed to a virtual function as follows in all
three classes?

/// Give panic message and exit the program. can be overridden in subclass
virtual void panic();

When exactly does panic() get called? It doesn't seem to be mentioned in the
parsers and lexers that I've generated. I assume that if panic() is called,
it's safe to throw an exception to escape from the parser, and delete the
parser, rather than being forced to exit() - which is often undesirable.

Thanks in advance

Ross.








 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list