[antlr-interest] Exception tests eat performance?

Ric Klaren klaren at cs.utwente.nl
Wed Jan 7 09:22:56 PST 2004


Hi,

On Wed, Jan 07, 2004 at 08:54:41AM -0800, Karl Meissner wrote:
> It seems that antlr uses exceptions in a lot of the generated parsers where
> simple test will do.  Everything that I have read is that an exceptions
> have a very high overhead and it is undesirable to generate them in a tight
> loop where they happen a lot.

You are right, yet the whole ANTLR 2 codegeneration is based around this
(in a sense it's a easy way to deal with some of the errors and with the
backtracking). Also makes ports to languages without exception handling
awkward. Another thing is that it increases codesize for C++ (need RTTI)
embedded software folks would probably love to have that turned off.

> Exceptions are used so extensivly it would require a big rewrite to change
> but I wanted to raise it as an issue

It's been raised before. Maybe it can be addressed in ANTLR 3 since the
whole codegen gets an overhaul then.

> where match throws an exception if the next token is not the parameter.
> Since match is just
> public virtual void  match(int t)
> {
>     if (LA(1) != t)
> 	throw new MismatchedTokenException(tokenNames, LT(1), t, false, getFilename());
>     else
> 	consume();
> }

That one is particularly ugly indeed. Yet it allows to do some tricks via
overloading of match. Bit of a tradeoff between extendability and
performance.

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  Xander: "Buffy, we need to do something *now*"
  Angel: "We need a distraction."
  Buffy: "Right."
  Angel: "What are you going to do?"
  Buffy: "I'm going to kill them all. That oughtta distract 'em..."

 

Yahoo! Groups Links

To visit your group on the web, go to:
 http://groups.yahoo.com/group/antlr-interest/

To unsubscribe from this group, send an email to:
 antlr-interest-unsubscribe at yahoogroups.com

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




More information about the antlr-interest mailing list