[antlr-interest] Re: Problem with Single Line Comments--solved

ramyasivadas ramyasivadas at yahoo.co.in
Wed May 14 01:56:36 PDT 2003


Hi,
Thank you for your response.
For eg, if the input is
 //file created in may for xyz -re.ist (comment)

 On encountering the - or ( or ), an exception was thrown.
But, i have now solved that by defining the SL_COMMENT and ML_COMMENT 
as follows:
SL_COMMENT
: "//"
(~('\n'|'\r'))* ('\n'|'\r'|'.'|'-'|'('|')'('\n')?)?
		{ _ttype = 

ANTLR_USE_NAMESPACE(antlr)Token::SKIP;}
;

ML_COMMENT
    :    "/*"
         (  { LA(2)!='/' }? '*'
		 | '.'|'-'|'('|')'
         | '\n' { newline(); }
         | ~('*'|'\n')
         )*
         "*/"
		{ _ttype = 

ANTLR_USE_NAMESPACE(antlr)Token::SKIP;}
    ;

Will post if i encounter some other problem.

Thanks and Regards,
Ramya


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> What is the input and what is the exception thrown?
> 
> Monty
> 
> -----Original Message-----
> From: ramyasivadas [mailto:ramyasivadas at y...]
> Sent: Monday, May 12, 2003 4:00 AM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Problem with Single Line Comments
> 
> 
> Hi,
> I have defined single line comment and multiline comment as follows:
> 
> SL_COMMENT
> : "//"
> (~('\n'|'\r'))* ('\n'|'\r'('\n')?)?
> 		{ _ttype = 
> 
> ANTLR_USE_NAMESPACE(antlr)Token::SKIP; }
> ;
> 
> ML_COMMENT
>     :    "/*"
>          (  { LA(2)!='/' }? '*'
>          | '\n' { newline(); }
>          | ~('*'|'\n')
>          )*
>          "*/"
> 		{ _ttype = 
> 
> ANTLR_USE_NAMESPACE(antlr)Token::SKIP; }
>     ;
> 
> When a file with the comments are parsed, an exception is thrown 
> depending on the string that appears following the "//" and 
the "/*" 
> characters.
> I just want the parser to ignore the string that follows 
immediately 
> after the "//" or "/*" till the newline is encountered.
> Can anyone please suggest me a solution for the problem.
> 
> Thanks in advance.
> Regards,
> Ramya
> 
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list