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

Terence Parr parrt at cs.usfca.edu
Sat Sep 10 17:34:28 PDT 2005


On Sep 10, 2005, at 3:16 PM, Oliver Zeigermann wrote:

> 2005/9/10, Terence Parr <parrt at cs.usfca.edu>:
>
>> No matter what, if you have a ref to a parameter in a predicate that
>> will end up in a cyclic DFA, it will not be visible!  There is
>> absolutely no way around this.  You can generate an arbitrary DFA in
>> java code without using ptrs to objects.  Many people have try to
>> show me some try-finally stuff that will do arbitrary gotos but I
>> always show a backwards jump that isn't possible.
>>
>
> Maybe I am missing something obvious, but why not making the inner
> classes non-static? This way you have the implied this pointer and can
> simply access the fields of the enclosing class.
>
> This actually worked for me!!!
>
> Turning something like
>
>         alt10 = DFA10.predict(input);
> to
>         alt10 = new DFA10().predict(input);

Hi Oliver,

Yep, I was opposed to creating that memory on each invocation, but  
now that I think about it, it would be not that bad for parsers as  
cyclic DFAs are uncommon.  However, the lexer would get crushed.  Can  
u imagine creating and extra object for every token?

There was a reason that I simply didn't pass in the "this" pointer as  
a parameter.  can't remember why.  Maybe it was because I couldn't  
see inside the code and figure out what variables had to have "this."  
prepended.  There was some really good reason I didn't do this.   
Sorry I can't remember.  Maybe my code has a comment...

Ter


More information about the antlr-interest mailing list