[antlr-interest] org.antlr.runtime.tree.RewriteEmptyStreamException

Andrew Haley aph at redhat.com
Wed Jul 7 09:22:45 PDT 2010


On 07/07/2010 05:19 PM, David Maier wrote:
> Hello,
> 
> 
> I am getting the following error message as Output of a tree generating grammar which I am currently writing. 
> 
> Exception in thread "main" org.antlr.runtime.tree.RewriteEmptyStreamException: rule sp_decls
>         at org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:158)
> 	at org.antlr.runtime.tree.RewriteRuleElementStream.nextTree(RewriteRuleElementStream.java:145)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.sp_block_content(MySQLASTGenParser.java:10730)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.sp_unlabeled_block(MySQLASTGenParser.java:9691)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.sp_proc_stmt(MySQLASTGenParser.java:8577)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.sp_tail(MySQLASTGenParser.java:1691)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.no_definer_tail(MySQLASTGenParser.java:1541)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.view_or_trigger_or_sp_or_event(MySQLASTGenParser.java:1401)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.create(MySQLASTGenParser.java:1260)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.stmt(MySQLASTGenParser.java:1186)
> 	at com.ingres.antlr.idiom.mysql.MySQLASTGenParser.prog(MySQLASTGenParser.java:1117)
> 	at __Test__.main(__Test__.java:16)
> 
> So the last rules are looking as the following:
> 
> sp_unlabeled_block:
>           
>           sp_block_content
>           
>         ;
> 
> sp_block_content:
>           BEGIN_SYM
>           
>           sp_decls
>           sp_proc_stmts
>           END  -> sp_decls sp_proc_stmts //To ignore the BEGIN and END
>         ;
> 
> sp_decls:  (sp_decl ';')* -> (sp_decl)*;
> 
> sp_decl:
> 	          DECLARE_SYM sp_decl_idents
> 	          
> 	          type
> 	          (sp_opt_default)? -> ^(TN_DECLARE ^(TN_PARAMS  sp_decl_idents type) ^(TN_TODO sp_opt_default)?)
> 	        
> 	          
> 	        | DECLARE_SYM ident CURSOR_SYM FOR_SYM sp_cursor_stmt ->  ^(TN_DECLARE ^(TN_NAME ident) ^(TN_SELECT sp_cursor_stmt))
> 	          
> 	        ;
> 
> 
> There is a TN_CODE token type which I want to use as the root node of the subtree which will then have this TN_DECLARE nodes as child nodes. So I only did rewrite the rules 'between' TN_CODE and TN_DECLARE to remove unnecessary information like the ';' or the BEGIN and END keywords.
>  
> So I guess that the error occurs because my test input does not have a DECLARE section, but this is OK because of the rule 'sp_decls:  (sp_decl ';')* -> (sp_decl)*;
> ' which says that there could be even no one (*=0 or multiple). So has anybody an answer what is causing the issue and how to solve it?

sp_decls might be void.  Try

sp_block_content:
          BEGIN_SYM
          
          sp_decls
          sp_proc_stmts
          END  -> sp_decls? sp_proc_stmts //To ignore the BEGIN and END
        ;



More information about the antlr-interest mailing list