[antlr-interest] ANTLR 3: Problem with static DFA class generation
Oliver Zeigermann
oliver.zeigermann at gmail.com
Sat Sep 10 15:16:50 PDT 2005
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);
and
public static int predict(IntStream input) throws RecognitionException {
to
public int predict(IntStream input) throws RecognitionException {
and
static DFA.State s17 = new DFA.State() {{alt=2;}};
to
DFA.State s17 = new DFA.State() {{alt=2;}};
and finally
static class DFA10 extends DFA {
to
class DFA10 extends DFA {
Not very elegant, but seems to work. Anything I am missing?
Thanks and cheers
Oliver
More information about the antlr-interest
mailing list