[antlr-interest] comment must be preceded by whitespace

charlesskelton c.skelton at skelton.de
Wed Mar 17 15:45:36 PST 2004


I'm new to antlr.

I'm trying to write lexer for a language, k, in which single line 
comments begin with a '/'. If there is no whitespace before the '/', 
or the '/' is not in column 1, then it is not a comment.

e.g

/this is a comment
   /this is also a comment
a:+/!10 /this text after the second forward slash is a comment

In this language, +/!10 actually means sum over numbers 0 thru 9, 
but that is not very relevant here, except it shows the other use 
of '/'.

I did try to define the comment as

SL_COMMENT
	:
            ((" /")  (~('\n'|'\r'))* ('\n'|'\r'('\n')?))
         |  (("\t/") (~('\n'|'\r'))* ('\n'|'\r'('\n')?))
         |  (("\f/") (~('\n'|'\r'))* ('\n'|'\r'('\n')?))
         |  {getColumn()==1}? (('/')  (~('\n'|'\r'))* 
('\n'|'\r'('\n')?))
	;

but it complains when the first char is not a '/'. I would define it 
as

          (("\n/")  (~('\n'|'\r'))* ('\n'|'\r'('\n')?))

but I need \n to match WS type.

Any help would be greatly appreciated.

Many thanks,
Charlie





 
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