Greetings!
On Sat, 2009-11-14 at 09:08 +0000, Scott Oakes wrote:
> Hoping for some newbie help on the following lexer.
> 
>   fragment DIGIT:      '0'..'9';
>   fragment LETTER: ('a'..'z'|'A'..'Z');
> 
>   ID:  (LETTER | '.')+ ('.' DIGIT+)?
>        | DIGIT+
>       ;
> 
> The idea is that ID is things like: "foo", "32", "bar.baz", or
> "foo.bar.32". However with input "foo.bar.32", I get two tokens,
> "foo.bar." and "32". How could I rewrite this so I get a single ID
> token, "foo.bar.32"?

the following almost works (tested with your samples)

ID : LETTER+ ( '.' LETTER+ )* ('.' DIGIT+)?
     | DIGIT+
     ;

this won't work for things like "." or "..32" or "car..cod" or "..."
which your original rule had POTENTIAL for recognizing. Did you mean for
those to be valid? if so maybe:

ID : LETTER* ( '.' LETTER* )+ DIGIT*
     | DIGIT+
     ;

Hope this helps
   -jbb



List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--

You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=.


Reply via email to