[antlr-interest] C++ exceptions in the ANTLR3 C target

Jim Idle jimi at temporal-wave.com
Thu Jan 15 10:23:49 PST 2009


Richard Thrippleton wrote:
> Now that the C target can be built by a C++ compiler, I've been trying 
> to throw C++-style exceptions (as opposed to the exception system 
> internal to ANTLR's C target) from within embedded actions.
>
> My grammars build successfully, and the exceptions seem to behave as I'd 
> expect at runtime. However, I suspect I'm leaving myself open to 
> undefined behaviour; are C++ exceptions within the C output actually 
> supported, or is it merely co-incidence that nothing horrendous has 
> happened?
>
> My main fear would be memory leaks, but I'm not 100% sure if this is 
> happening or not.
>   
You can probably use them carefully, but as you point out, you have to 
be careful with memory. The runtime tracks all its normal memory 
allocations so  as long as you close the 'classes' correctly you should 
generally be OK. However, you should make sure that throwing exceptions 
does not bypass the normal rule clean up, such as resetting error and 
backtracking flags and so on,

Jim


More information about the antlr-interest mailing list