[antlr-interest] ANTLR 3: Problem with static DFA class generation

Oliver Zeigermann oliver.zeigermann at gmail.com
Mon Sep 19 02:22:15 PDT 2005


2005/9/18, Terence Parr <parrt at cs.usfca.edu>:
> 
> 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!

Yes, that's right! My patch does not include the above single
construction, as this would have required a bit more than changing a
template, though. But I am pretty sure that you know how to do this...

Oliver


More information about the antlr-interest mailing list