[antlr-interest] Re: check tokens for whitespace?

kozchris csnyder at alumni.ncsu.edu
Thu Sep 23 16:42:42 PDT 2004


Something like this is one way.

class LTest extends Lexer;

tokens {
  FUNC;
}

VAR : ("plus" ('a'..'z'|'0'..'9')) => ('a'..'z') ('a'..'z'|'0'..'9')*
  | ("plus")=> "plus" {$setType(FUNC);};

WS : ( ' '| '\t' | '\f') { $setType(Token.SKIP); }

Chris

--- In antlr-interest at yahoogroups.com, "mazypath" <eitan at c...> wrote:
> Sorry if this is a newbie question but I can't seem to find an answer
> in the docs or online.
> 
> Is there anyway to define a token as a string and to only have have
> that string recognized as a token if it is not followed by whitespace?
> 
> For example if I define the Lexer as follows:
>   class L extends Lexer;
> 
>   FUNC : "plus";
>   WS : ( ' '| '\t' | '\f') { $setType(Token.SKIP); }
>   VAR : ('a'..'z') ('a'..'z'|'0'..'9')*;
>   ;   
> 
> Can I get the Lexer to parse the string "plus1" as a VAR token and not
> a FUNC token followed by "1"?
> 
> Thanks in advance!



 
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