[antlr-interest] how to do exceptions quickly

Benjamin Niemann pink at odahoda.de
Sun Nov 4 01:16:28 PDT 2007


Hi,

Terence Parr wrote:
> I had a long conversation at Google last night with Neal Gafter, the guy 
> who built the javac compiler when he was at Sun. He told me that 
> exceptions can be made to execute very quickly.  The only thing you have 
> to avoid is the actual exception object creation which has to do all of 
> the expensive stack trace creation and so on.  He says that the actual 
> throwing of the exception itself is not a problem.  This might be 
> something to look at later to see if it goes quickly, because it results 
> in cleaner backtracking code.  Anyway, we can create some singleton 
> objects, which will solve the problem.  Hooray!
> 
> Anyway, this might be useful to people in general.  I thought was pass 
> along this interesting trick.

As a follow-up to this long forgotten thread: I just replaced the failed 
flag by a BacktrackingFailed exception in my Python target. I got rid of 
all flag checking reducing the file size of the generated parser by ~5% 
and having a small performance gain of about ~2 (using the Java.g parser).
If you are interested, look at CL 4272.


Bye,
  Ben



More information about the antlr-interest mailing list