[antlr-interest] ANTLR 3: No way to specify member variables for embedded lexer

Terence Parr parrt at cs.usfca.edu
Sat Sep 10 10:50:03 PDT 2005


On Sep 9, 2005, at 9:21 AM, Oliver Zeigermann wrote:
> If you have a combined lexer/parser grammar there seems to be no way
> to specify additional member variables for the lexer like this:
>
> grammar XML;
> {
>
>     boolean textMode = false;
> }
>
> This is possible only if you split the grammar. Any better solutions?

I have spent a LONG time trying to figure out what to do here.  We  
really need a solution that allows a combined grammar to push  
instance variables to the lexer object.  I considered the named  
action thing we use for C++ headers:

header "X" {
   action for output location X
}

Should we do something similar?  There is no keyword though and this  
is wacky:

"lexer" {
   boolean textMode = false;
}

perhaps

action "lexer" {
   boolean textMode = false;
}

or perhaps we should have

fields "lexer" {
   boolean textMode = false;
}

or something to make it more explicit.  what about methods in there?   
Is there a more generic term?  Maybe "action" is the right term. Hmm...

We definitely need a solution here.

Ter
--
CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com



More information about the antlr-interest mailing list