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

Andrew Haley aph at redhat.com
Wed Jul 7 09:49:01 PDT 2010


On 07/07/2010 05:42 PM, David Maier wrote:

> 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)*;

That part is fine.  sp_block_content, however, don't know that sp_decls
might return a void result.

> 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?

Did you try it?  If so, did it work?

The rewrite rules are not part of the formal grammar as such, and you may
need to do things you don't expect.

As to whether this is an ANTLR bug, I don't know.  I can't find anything
in the spec one way or the other.

Andrew.


More information about the antlr-interest mailing list