[antlr-interest] RewriteEmptyStreamException when changing from quoted string to token?

Jon Schewe jpschewe at mtu.net
Mon Jan 14 12:26:26 PST 2008


I just got time to get back to this project, been stuck on a different 
one.  I tried your suggestion of gathering everything up in a variable 
and that didn't help.  Still the same error. 

/**
 * @param negate if true, negate all expressions by multiplying by -1
 */   
multExpr[boolean negate]
    :   a+=atom (PRODUCT a+=atom)* -> {negate}? ^(PRODUCT ^(NUMBER 
DOUBLE["-1"]) $a)
                                   ->           ^(PRODUCT $a)
    ;

    [junit]     Caused an ERROR
    [junit] token PRODUCT
    [junit] org.antlr.runtime.tree.RewriteEmptyStreamException: token 
PRODUCT
    [junit]     at 
org.antlr.runtime.tree.RewriteRuleElementStream._next(RewriteRuleElementStream.java:158)
    [junit]     at 
org.antlr.runtime.tree.RewriteRuleTokenStream.next(RewriteRuleTokenStream.java:57)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.GHOCESParser.multExpr(GHOCESParser.java:3518)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.GHOCESParser.addExpr(GHOCESParser.java:3311)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.GHOCESParser.constraintDecl(GHOCESParser.java:2312)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.GHOCESParser.constraints(GHOCESParser.java:1972)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.GHOCESParser.constraintDecls(GHOCESParser.java:733)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.GHOCESParser.program(GHOCESParser.java:168)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.GHOCES.parseFile(GHOCES.java:401)
    [junit]     at 
com.honeywell.htc.schedinfra.pconstraint.parser.test.TestParser.test1(TestParser.java:85)

Mark Wright wrote:
> Hello Jon,
>
> Here is an example stack trace of the exception:
>
> Exception in thread "main" org.antlr.runtime.tree.RewriteEarlyExitException
>         at tntdbo.dboc.TntdboParser.template_parameter_list(TntdboParser.java:15830)
>         at tntdbo.dboc.TntdboParser.template_declaration(TntdboParser.java:15677)
>         at tntdbo.dboc.TntdboParser.declaration(TntdboParser.java:5443)
>         at tntdbo.dboc.TntdboParser.declaration_seq(TntdboParser.java:5327)
>         at tntdbo.dboc.TntdboParser.namespace_body(TntdboParser.java:9378)
>         at tntdbo.dboc.TntdboParser.original_namespace_definition(TntdboParser.java:9142)
>         at tntdbo.dboc.TntdboParser.named_namespace_definition(TntdboParser.java:9053)
>         at tntdbo.dboc.TntdboParser.namespace_definition(TntdboParser.java:8958)
>         at tntdbo.dboc.TntdboParser.declaration(TntdboParser.java:5471)
>         at tntdbo.dboc.TntdboParser.declaration_seq(TntdboParser.java:5327)
>         at tntdbo.dboc.TntdboParser.translation_unit(TntdboParser.java:243)
>         at tntdbo.dboc.Tntdboc.process(Tntdboc.java:99)
>         at tntdbo.dboc.Tntdboc.<init>(Tntdboc.java:39)
>         at tntdbo.dboc.Tntdboc.main(Tntdboc.java:65)
>
> So I open up the 1.2 MB generated Java parser source file in emacs,
> (as netbeans just hangs when trying to open it), and go to line 15830
> from the stack trace above.  The relevant fragment is below.
> Then I look above the line where the RewriteEarlyExitException
> was thrown, to the comment that ANTLR helpfully generated for
> me to let me know the line in my grammar where I screwed up.
>
> // AST REWRITE
> // elements: template_parameter
> // token labels: 
> // rule labels: retval
> // token list labels: 
> // rule list labels: 
> retval.tree = root_0;
> RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);
>
> root_0 = (TntdboAST)adaptor.nil();
> // 1175:17: -> ^( TEMPLATE_PARAM ( template_parameter )+ )
> {
>     // Tntdbo.g:1175:20: ^( TEMPLATE_PARAM ( template_parameter )+ )
>     {
>     TntdboAST root_1 = (TntdboAST)adaptor.nil();
>     root_1 = (TntdboAST)adaptor.becomeRoot((TntdboAST)adaptor.create(TEMPLATE_PARAM, "TEMPLATE_PARAM"), root_1);
>
>     if ( !(stream_template_parameter.hasNext()) ) {
>         throw new RewriteEarlyExitException();          <=== line 15830
>     }
>     while ( stream_template_parameter.hasNext() ) {
>         adaptor.addChild(root_1, stream_template_parameter.nextTree());
>
>     }
>     stream_template_parameter.reset();
>
>     adaptor.addChild(root_0, root_1);
>     }
>
> }
>
> I look at that line:
>
> template_parameter_list
>   :   template_parameter ( ',' template_parameter )*
>           -> ^(TEMPLATE_PARAM template_parameter+)      <=== line 1175
>   ;
>
> and I guess it is wrong, it does not like the plus in the AST rewrite.
> I tried changing it to:
>
> template_parameter_list
>   :   l+=template_parameter ( ',' l+=template_parameter )*
>           -> ^(TEMPLATE_PARAM $l)      <=== line 1175
>   ;
>
> It then gets past the RewriteEarlyExitException (to another issue in my grammar).
>
> I hope this gives some hints on how to debug it.
>
> Regards, Mark
>
>   

-- 
Jon Schewe | http://mtu.net/~jpschewe
If you see an attachment named signature.asc, this is my digital
signature.
See http://www.gnupg.org for more information.

For I am convinced that neither death nor life, neither angels 
nor demons, neither the present nor the future, nor any 
powers, neither height nor depth, nor anything else in all 
creation, will be able to separate us from the love of God that 
is in Christ Jesus our Lord. - Romans 8:38-39



More information about the antlr-interest mailing list