[antlr-interest] Re: comment field

Tak-po Li takpoli at hotmail.com
Wed Feb 16 13:35:54 PST 2005


1. Does anyone has experience to preserve the comments?  Some tools (ASIC 
synthesis) use information in the comment field for control.  We would like 
the comment field be saved in AST tree as a tail node, in the original 
position of the source tree.  Could it be done?

2. One more thing, I cut and use the following JAVA multiple line comment 
logic:

// multiple-line comments
ML_COMMENT
	:	"/*"
		(	/*	'\r' '\n' can be matched in one alternative or by matching
				'\r' in one iteration and '\n' in another.  I am trying to
				handle any flavor of newline that comes in, but the language
				that allows both "\r\n" and "\r" and "\n" to all be valid
				newline is ambiguous.  Consequently, the resulting grammar
				must be ambiguous.  I'm shutting this warning off.
			 */
			options {
				generateAmbigWarnings=false;
			}
		:
			{ LA(2)!='/' }? '*'
		|	'\r' '\n'		{newline();}
		|	'\r'			{newline();}
		|	'\n'			{newline();}
		|	~('*'|'\n'|'\r')
		)*
		"*/"
		{$setType(Token.SKIP);}
	;

I came across with character '"' (double quot) fails.  Has anyone experience 
with this?  Could someone points me the best way to debug my problem?

Tak




More information about the antlr-interest mailing list