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

Oliver Zeigermann oliver.zeigermann at gmail.com
Mon Sep 19 04:21:10 PDT 2005


OK, I created patches for the new Java.stg, DFA.java (optional - makes
predicat non-static) and finally a small one for Codegenerator.java.
Using them will generate the code below.

Oliver

2005/9/19, Oliver Zeigermann <oliver.zeigermann at gmail.com>:
> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Java.stg.diff
Type: application/octet-stream
Size: 5117 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050919/0f46111d/Java.stg-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DFA.java.diff
Type: application/octet-stream
Size: 306 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050919/0f46111d/DFA.java-0001.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CodeGenerator.java.diff
Type: application/octet-stream
Size: 569 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050919/0f46111d/CodeGenerator.java-0001.obj


More information about the antlr-interest mailing list