[antlr-interest] "finally" blocks
Paul J. Lucas
pauljlucas at mac.com
Mon Jan 17 15:37:53 PST 2005
On Mon, 17 Jan 2005, Terence Parr wrote:
> Interesting...was wondering how to do that in C++. I wonder if it's
> general though.
It's trivial to make a templated "flag" class that takes any
> A finally clause can play with all sorts of local variables and call methods
I don't have Bjarne's book in front of me, but he talks about
the general concept is about resource aquisition and release
(which is mostly what "finally" in Java is used for, e.g., open
a file, make sure it's closed, etc.).
In practice, "finally" code generally only needs to reset a
small number of things, so it's not as bad as you might think.
> Would ANTLR need to analyze C++ actions (shudder) in order to construct the
> bool_flag(arglist) thing? Probably.
In ANTLR for C++, you don't need "finally" at all because if
the user wants the functionality, s/he can simply do what I
did, i.e., create a variable having a destructor.
The only reason I want "finally" in ANTLR is because I'm using
Java (only because I'm paid to) and Java needs "finally".
But this implies that ANTLR for Java and ANTLR for C++ would be
More information about the antlr-interest