[antlr-interest] Trouble with comma separated list
Jason
jasonriz at yahoo.com
Wed Feb 18 12:22:23 PST 2004
Nevermind, I solved it myself. Sorry to have wasted
your time.
-jason
--- Jason <jasonriz at yahoo.com> wrote:
> Hello,
>
> I've written the following simple grammar to process
> a
> list of 'where's.
>
> //BEGIN GRAMMAR
> class P extends Parser;
>
> startRule
> :
> item_list;
>
> item_list:
> item { System.out.println("item_list : item"); }
> (COMMA item)* { System.out.println("item_list :
> (COMMA item)*"); }
> ;
>
> item : WHERE { System.out.println("item : WHERE");
> }
> ;
>
> class L extends Lexer;
>
> tokens
> {
> WHERE = "where";
> COMMA = ",";
> }
>
> NAME options { testLiterals=true; } : (',' |
> 'a'..'z'|'A'..'Z')+ { } //NEWLINE
> ;
>
> // Whitespace -- ignored
> WS : ( ' '
> | '\t'
> | '\f'
> // handle newlines
> | ( options {generateAmbigWarnings=false;}
> : "\r\n" // Evil DOS
> | '\r' // Macintosh
> | '\n' // Unix (the right way)
> )
> { newline(); }
> )+
> { _ttype = Token.SKIP; }
> ;
> //END GRAMMAR
>
> This handles input of the following form:
>
> 'where , where , where , where'
>
> but chokes on something like:
>
> 'where , where, where'
>
> In other words it requires that there be a space
> between the 'where' token and the ',' token. I
> understand why this is happening but it's not clear
> to
> me how to fix it. If anyone can point me towards
> the
> relevent option (or some other solution), I'd
> greatly
> appreciate it. Thanks.
>
> -jason
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail SpamGuard - Read only the mail you want.
> http://antispam.yahoo.com/tools
>
>
>
> Yahoo! Groups Links
>
>
> antlr-interest-unsubscribe at yahoogroups.com
>
>
>
__________________________________
Do you Yahoo!?
Yahoo! Mail SpamGuard - Read only the mail you want.
http://antispam.yahoo.com/tools
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