[antlr-interest] Re: second lexical pass

idontwantanidwith2000init idontwantanidwith2000init at yahoo.com
Sun Apr 11 11:43:29 PDT 2004


I've ment multiple values of course :)
That's what I wanted to do, Terr, more or less. :)
I'm sad though. With lex I could handle it without a second parser.
But it seems a better aproch then putting it all together in one 
parser.
Let me explain why:
'"'YYYY-MM-DD hh:mm:ss'"' is a STRING.
and there isn't a simple way to express this relationship.
Maybe it's an idea for improving the lexer.

What do you think?

--- In antlr-interest at yahoogroups.com, Terence Parr <parrt at c...> 
wrote:
> 
> On Apr 11, 2004, at 6:25 AM, idontwantanidwith2000init wrote:
> 
> > Is there an elegant way to do a second lexical path instead of
> > writing two lexers?
> >
> > For instance:
> > STRING_LITERAL:
> > '"' (~('\r'|'n'|'\\') | '\\' .) '"' ;
> >
> > now STRING_LITERAL will colide with any special string you'd 
like to
> > match, for instance:
> > DATE_TIME : '"'YYYY-MM-DD hh:mm:ss'"'
> >
> > I've managed to merge it with:
> > '"'(LETTER)*'"'
> > '"'(LETTER)*'.'(LETTER)*'"'
> > '"'(LETTER)*'-'(LETTER)*'"'
> > Which was a diffucult task but doable.
> >
> >
> > I thought about it and merging these rules is possible, but it 
will
> > take me days to write it and we haven't talked about validation.
> > (It is a good to write down my thoughts I'm starting to convince
> > myself that it is a good idea)
> >
> > What do you think is a proper solution?
> 
> My first thought is that you have a two-level grammatical issue 
here.  
> First you have to match a string and then determine if it 
satisfies a 
> "nested structure" which is the date/time stuff.  You can't really 
use 
> another rule in the same lexer object as it will consume the 
input.  
> Perhaps a compromise.  Make a new lexer rule that will match 
DATE_TIME 
> as you've done and make it protected.  Then, make a *new* instance 
of 
> your lexer.  Set it up with a copy of the text matched inside the 
> string and then directly call DATE_TIME with a try/catch around it 
to 
> catch failure.  Gotta love LL based lexers :)
> 
> Ter
> --
> Professor Comp. Sci., University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
> Cofounder, http://www.knowspam.net enjoy email again!
> Cofounder, http://www.peerscope.com pure link sharing



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list