[antlr-interest] two (simple?) questions

ali azimi aliaazimi at yahoo.com
Mon Sep 3 19:22:28 PDT 2007


Hi,
   
  Try this one. Please tell me if it works for you.
  grammar G;
options {
backtrack=true;
language=Java;
}
@members {
String s;
}
  digit :(ALPHANUMERIC |WS ) * ; 
ALPHANUMERIC : (DIGIT | LOWER | UPPER | '_') +  ;
LOWER       :'a'..'z' ;
UPPER       :'A'..'Z' ;
DIGIT: '0'..'9' ;
WS : (' ' |'\t' |'\n' |'\r' )+ {skip();} ;


Jerry Ro <jerrro at gmail.com> wrote:
    Hi,
   
  I was wondering if anyone can help with two simple (newbie) questions:
   
  The first is:
  I define in the Lexer rules the following rule for defining alphanumeric strings:
   
  ALPHANUMERIC : (DIGIT | LOWER | UPPER | '_')+ ;
   
  where digit is a fragement of 0..9 and lower and upper are fragments of a to z and A to Z. However, strings which are just numbers are not accepted as "alphanumeric". I have to add a lower case letter for the parser to accept the string according to the alphanumeric rule, but I would expect a just numbers string to match the alphanumeric lex rule. 
   
  Second thing is:
  How do I make the parser parse even if there are no spaces between the tokens? Right now I have to separate all tokens with spaces in order for the parser to parse anything... I do have a rule of the following form: 
  WHITESPACE : ( '\t' | ' ' | '\r' | '\n'| '\u000C' )+    { $channel = HIDDEN; } ;
  in the lexer rules.
   
   
  Thanks
   
   
   
  Jerr
   


       
---------------------------------
Luggage? GPS? Comic books? 
Check out fitting  gifts for grads at Yahoo! Search.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070903/1a914122/attachment.html 


More information about the antlr-interest mailing list