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

David Maier David.Maier at ingres.com
Wed Jul 7 09:42:20 PDT 2010


Hi again,


thanks for your quick reply Andrew. But shouldn't the following rule be enough to make ANTRL aware of that it can be void:

sp_decls:  (sp_decl ';')* -> (sp_decl)*;

I mean that the Kleene operator (*) means to also match the empty word, right? So I think the following is true for rules named 'a', 'b' and 'c':


(1) My variant

a : b;
b : c*;


with

c* := /*empty*/ | c+

and if I resolve it then 'a' means:

a: /*empty*/ | c+


(2) Your variant

a: b?;
b: c*;

with

b?:= /*empty*/ | b

b:= /*empty*/ | c+

and so 

a:= /*empty*/ | /*empty*/ | c+ := /*empty*/ | c+


So you can see that both should mean the same. So is it a kind of ANTLR issue that I would have to use the (?) operator here?


Regards, David

--
David Maier
Senior Software Engineer

Ingres Germany GmbH
Weimarer Straße 1a
D-98693 Ilmenau

PHONE:  +49.3677.6785-59
FAX:    +49.3677.6785-23
MAIL:   david.maier at ingres.com

This transmission is confidential and intended solely for the use of the recipient named above. It may contain confidential, proprietary, or legally privileged information. If you are not the intended recipient, you are hereby notified that any unauthorized review, use, disclosure or distribution is strictly prohibited. If you have received this transmission in error, please contact the sender by reply e-mail and delete the original transmission and all copies from your system.



-----Ursprüngliche Nachricht-----
Von: antlr-interest-bounces at antlr.org im Auftrag von Andrew Haley
Gesendet: Mi 07.07.2010 18:22
An: antlr-interest at antlr.org
Betreff: Re: [antlr-interest]org.antlr.runtime.tree.RewriteEmptyStreamException
 
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
        ;


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