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

mzukowski at yci.com mzukowski at yci.com
Wed May 14 08:34:32 PDT 2003


Good try, but the problem is probably completely different.  Try setting the
charVocabulary option for the lexer.  For example:

options{
charVocabulary = '\3'..'\377'
}

Antlr didn't know to include - ( or ).  By default it only includes
characters you specifically name in the lexer or parser.  Setting this
option as above tells it to include all ASCII chars except \0 \1 and \2
which antlr reserves for its own use though I can't remember exactly why
right now...

Monty


-----Original Message-----
From: ramyasivadas [mailto:ramyasivadas at yahoo.co.in]
Sent: Wednesday, May 14, 2003 1:57 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] Re: Problem with Single Line Comments--solved


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/ 


 

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




More information about the antlr-interest mailing list