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

Oliver Zeigermann oliver.zeigermann at gmail.com
Fri Sep 9 09:12:54 PDT 2005


Folks,

I have a problem with code looking like this:

lexer grammar XMLLexer;
{
    boolean tagMode = false;
}

TAG_START_OPEN : { !tagMode }? '<' { tagMode = true; } ;
TAG_END_OPEN : { !tagMode }? "</" { tagMode = true; } ;

....


The generated code does not work, as the inner static DFA classes try
to access tagMode oif the outer class to check the semantic predicate
which of course does not work.

Writing it this way does work, but that's silly isn't it?

lexer grammar XMLLexer;
{
    public static boolean tagMode = false;
}

TAG_START_OPEN : { !XMLLexer.tagMode }? '<' { XMLLexer.tagMode = true; } ;
TAG_END_OPEN : { !XMLLexer.tagMode }? "</" { XMLLexer.tagMode = true; } ;

...

I am willing to adjust the templates and know how to do that, but what
should they look like? Any ideas?

Oliver


More information about the antlr-interest mailing list