[antlr-interest] RE: Lexer: C-style comments with DOS/UNIX newlines
Nigel Sheridan-Smith
nbsherid at secsme.org.au
Thu Aug 19 19:48:43 PDT 2004
> -----Original Message-----
> From: Nigel Sheridan-Smith [mailto:nbsherid at secsme.org.au]
> Sent: Friday, 20 August 2004 12:43 PM
> To: 'antlr-interest at yahoogroups.com'
> Subject: Lexer: C-style comments with DOS/UNIX newlines
>
>
> 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();}
> | .
> )*
> "*/";
>
Just worked it out for myself, by looking at ANTLR's own grammar:
'antlr.g'... I changed it to the following:
/* COMMENT rules */
CCOMMENT: "/*"
( options {greedy=false; generateAmbigWarnings=false;}
: '\r' {newline();}
| '\r' '\n' {newline();}
| '\n' {newline();}
| ~('\n' | '\r')
)*
"*/";
Thanks anyway!! I'm sure I will have another question soon enough :)
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/
More information about the antlr-interest
mailing list