[antlr-interest] Lexer: C-style comments with DOS/UNIX newlines

Nigel Sheridan-Smith nbsherid at secsme.org.au
Thu Aug 19 19:43:21 PDT 2004


Hi there,

I'm a relative newcomer to ANTLR. I am trying to define C/C++/Java style
comments, and having some trouble.

I have the following rule, similar to that in the manual (with k=3 and ANTLR
2.7.4):


/* COMMENT rules */
CCOMMENT: "/*"
        ( options {greedy=false;}
        
         : '\r' ('\n')? {newline();}
         | '\n' {newline();}
         | . 
        )*
       "*/";



I get the following messages:

ANTLR Parser Generator   Version 2.7.4   1989-2004 jGuru.com
PersistenceGrammar.g:70:17: warning:lexical nondeterminism between alts 1
and 2 of block upon
PersistenceGrammar.g:70:17:     k==1:'\n'
PersistenceGrammar.g:70:17:     k==2:'\t','\n','\r','
'..'"','%'..'?','A'..'_','
a'..'~'
PersistenceGrammar.g:70:17:     k==3:'\t','\n','\r','
'..'"','%'..'?','A'..'_','
a'..'~'


If I remove the  ('\n')?  from the 5th line then the problem goes away.
However, this isn't actually what seems to be reported as the error.
Changing the "/*" and "*/" to "{" and "}" do not make any difference; nor
does increasing the value of k in the lexer.

Any help would be appreciated! The rest of the grammar is attached.

Thanks

Nigel

--
Nigel Sheridan-Smith
PhD research student

Faculty of Engineering
University of Technology, Sydney
Phone: 02 9514 7946
Fax: 02 9514 2435
 



 
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/
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PersistenceGrammar.g
Type: application/octet-stream
Size: 2668 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20040820/24586013/PersistenceGrammar.obj


More information about the antlr-interest mailing list