[antlr-interest] ANTLR 3: Problem with static DFA class generation
Terence Parr
parrt at cs.usfca.edu
Sat Sep 17 15:21:17 PDT 2005
On Sep 12, 2005, at 3:41 AM, Oliver Zeigermann wrote:
> It simple makes all DFA code non static to allow full access to the
> outer class' (Lexer) fields. The part that creates a single DFA per
> decision and lexer like this:
>
> class XMLLexer extends Lexer {
>
> ...
>
> private dfa10 = new DFA10();
>
> ...
>
> alt10 = dfa10.predict(input);
>
> ...
>
> }
Ok, I think figured out why I didn't want to do this before. There
is a bunch of state construction "new" operations that go on when you
say new DFA10(). I only wanted them to occur once as they are
expensive. I somehow missed the obvious reuse of the outermost DFA
object; here you are using dfa10 to create DFA10 just once. In this
way, we only create the DFA states once like with static, but the
inner classes have an implied "this" pointer and can see the instance
variables of the outer Lexer object. I like it!
Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com
More information about the antlr-interest
mailing list