[antlr-interest] Help with Java grammar

cliftonccraig ccc at icsaward.com
Mon Mar 8 14:18:23 PST 2004


Hello all,

I am a novice at ANTLR and have managed to get a Java source code
augmenting tool working after reading the article on
TokenStreamRewriting. What I'm having trouble with is the Java grammar
that I've modified from the ANTLR site. In order to get my augmenter
working I had to modify the JavaLexer and tell it not to ignore
whitespace and single line comments. I needed these tokens to flow
through to the rewrite engine. Now I have a scenario where a Java
source file is terminated with a single line comment"//". This seems
to confuse the Lexer and cause an OutOfMemory error. Could one of you
gurus help me tweak the grammar to avoid this? I'm not sure if I
should code an alternate for the single line comment rule like this:

// Single-line comments
SL_COMMENT
	:	"//"
		(~('\n'|'\r'))* ('\n'|'\r'('\n')?)
		{
//*CCC- Allow comments to flow through to the rewrite engine
//		    $setType(Token.SKIP);
		    newline();
		}
                |
                "//" EOF
	;
or even if that makes sense. I was also considering removing the
newline characters from the definition but I don't know what kind of
side effects that would have on the grammar. I'm just too nervous to
disturb the original grammar too much without know what's going on. Help! 

Thanks in advance,
Cliff



 
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