[antlr-interest] Issues with DOC comments --was [Multiline comments in ANTLR grammar]

Stefan Mätje Stefan.Maetje at esd-electronics.com
Wed Mar 7 05:51:52 PST 2012


Hi,

ANTLR reacts not very gracefully on DOC comments i. e. "/** bla bla */"

Another issue besides the one described by you is the case if you have two DOC 
comments between two rules. That will fail also with a syntax error.

I had the case when I commented a (unused) rule out without touching the DOC 
comments. Then I had two DOC comments between two valid rules that lead also 
to lots of syntax errors.

It took me quite some time to figure out what the reason for this odd 
behaviour was.

Regards,
	Stefan

Am 07.03.2012 14:01:17 schrieb(en) Ivan Brezina:
> Hi,
> I spotted curious issue, there must not be any multiline comment  
> between the grammar name
> and the options clause.
> see:
> --- begin snap ---
> lexer grammar abc;
> 
> /** (note two asterisks here)
>   * some fancy header
>   */
> 
> @lexer::members
> {
> bool x;
> }
> 
> A: 'A';
> --- end snap ---
> 
> This fails with:
> error(100): abc.g:7:1: syntax error: antlr: NoViableAltException(53@[])
> error(100): abc.g:7:2: syntax error: antlr: NoViableAltException(4@[])
> error(100): abc.g:7:7: syntax error: antlr:  
> MissingTokenException(inserted [@-1,0:0='<missing ACTION>',<50>,7:6]  
> at :)
> error(100): abc.g:7:8: syntax error: antlr: NoViableAltException(54@[])
> error(100): abc.g:7:9: syntax error: antlr: NoViableAltException(75@[])
> error(100): abc.g:7:9: syntax error: antlr: NoViableAltException(75@[])
> error(100): abc.g:12:1: syntax error: antlr:  
> MissingTokenException(inserted [@-1,0:0='<missing SEMI>',<52>,12:0] at  
> A)
> error(100): abc.g:0:1: syntax error: assign.types:  
> MismatchedTreeNodeException(0!=30)
> error(100): abc.g:0:1: syntax error: assign.types:  
> MismatchedTreeNodeException(42!=3)
> error(100): abc.g:0:1: syntax error: assign.types:  
> MismatchedTreeNodeException(42!=3)
> org\antlr\grammar\v3\DefineGrammarItemsWalker.g: node from line 3:0  
> mismatched tree node: <unexpected: [@11,56:56='@',<53>,7:0], resync=@>  
> expecting ID
> error(10):  internal error: abc.g : java.lang.NullPointerException
> org.antlr.tool.Grammar.generateMethodForRule(Grammar.java:1718)
> org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:1468)
> org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec
> (CodeGenTreeWalker.java:1441)
> org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:461)
> org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:421)
> org.antlr.Tool.generateRecognizer(Tool.java:655)
> org.antlr.Tool.process(Tool.java:468)
> org.antlr.Tool.main(Tool.java:93)
> 
> While this compiles successfully:
> ---------------------
> lexer grammar abc;
> 
> //
> // some fancy header
> //
> 
> @lexer::members
> {
> bool x;
> }
> 
> A: 'A';
> ---------------------
> /**
>    * some fancy header
>    */
> 
> lexer grammar abc;
> 
> @lexer::members
> {
> bool x;
> }
> 
> A: 'A';
> ---------------------
> 
> 
> Ivan
> 
> 
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
> 
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-
> address
> 
> 




More information about the antlr-interest mailing list