[antlr-interest] Inexplicable RewriteEmptyStreamException in parser grammar

Richard Thrippleton richard.thrippleton at progress.com
Wed May 26 08:46:28 PDT 2010


False alarm. There was some subtle abuse going on deep down in our setup of 
the parser (our tree adaptor was creating error nodes incorrectly). Apologies!

Richard

Richard Thrippleton wrote:
> I'm using the Java target with ANTLR 3.2, and having a problem in a rule in my parser grammar that looks like this:
> 
> "variableInit [ String name ]
>   : ASSIGNMENT id=initializer
>     -> ^(ASSIGNMENT IDENTIFIER[$ASSIGNMENT, $name] initializer)"
> 
> In a particular case where the 'initializer' rule fails to match and issues a syntax error, I'm getting a RewriteEmptyStreamException that cites "rule initializer" popping up from a line that looks like this:
> 
> "// 1151:5: -> ^( ASSIGNMENT IDENTIFIER[$ASSIGNMENT, $name] initializer )
> {
>   {
>     CommonTree root_1 = (CommonTree)adaptor.nil();
>     root_1 = (CommonTree)adaptor.becomeRoot(stream_ASSIGNMENT.nextNode(), root_1);
>     adaptor.addChild(root_1, (CommonTree)adaptor.create(IDENTIFIER, ASSIGNMENT179, name));
>     adaptor.addChild(root_1, stream_initializer.nextTree());           <-------------------- ****This line****
>     adaptor.addChild(root_0, root_1);
>   }
> }"
> 
> In terms of error handling we're just using the default recovery (not overriding it with 'catch'/'rulecatch'). We've overridden reportError to pretty-print the RecognitionExceptions, but that's about it. Should I be needing to do anything special to cope with parsing failures of subrules, or should the default be sufficient to prevent these exceptions? Otherwise, where is the problem likely to lie - a defect elsewhere in my grammar, or in ANTLR?
> 
> Cheers,
> Richard
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


-- 
\o/


More information about the antlr-interest mailing list