[antlr-interest] second lexical pass

jbb at acm.org jbb at acm.org
Sun Apr 11 10:48:17 PDT 2004


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?

I may be answering the wrong question here...

Do you want DATE_TIME to match multiple strings, say "2004-04-11 13:41:52"
and "2004-04-11 13:41:53" and ... ?

Or do you want DATE_TIME to be just the single, literal, string
"YYYY-MM-DD hh:mm:ss" ?

If it is the former (multiple values) then you can skip the rest of this
message and please accept my apologies for wasting your time.

If it is just a single string then I believe that this is the same issue
that often arises with keywords matching identifer. And Antlr has a pretty
good way of solving that issue. Try:

class Tryit extends Lexer;

tokens {
    DATE_TIME = "\"YYYY-MM-DD hh:mm:ss\"";
}

STRING_LITERAL
    options{
        testLiterals=true;
    } :
    '"' (~('\r'|'n'|'\\') | '\\' .) '"'
;





Hope this helps...
	-jbb


 
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