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

Johannes Luber jaluber at gmx.de
Fri Jan 4 13:31:17 PST 2008


Ola Bini schrieb:
> Jon Schewe wrote:
>> I have the following parser rule and lexer rule (others exist as
>> well). I'm using antlr 3.0.1.  If I change '*' in multExpr to PRODUCT
>> then at
>> runtime I get an exception.  If I leave it at '*', all is fine.  What am
>> I doing wrong here?
>>    [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)
>>
>>  
>>
>> /**
>>  * @param negate if true, negate all expressions by multiplying by -1
>>  */   multExpr[boolean negate]
>>     :   atom ('*' atom)* -> {negate}? ^(PRODUCT ^(NUMBER DOUBLE["-1"])
>> atom+)
>>                              ->           ^(PRODUCT atom+)
>>     ;
>>
>> PRODUCT         :   '*'     ;
>>   
> I have seen the same problem, and have no idea why this happens.
> 

The reason is simple: '*' and PRODUCT have different tokens. If you
change a literal to a token, then change all occurrences of it. You have
overlooked '*' in "atom ('*' atom)*".

Johannes


More information about the antlr-interest mailing list