[antlr-interest] ANTLR 3.1 gives RewriteEmptyStreamException, ANTLR3.0.1 does not ?

Terence Parr parrt at cs.usfca.edu
Mon Sep 29 13:47:37 PDT 2008


On Sep 29, 2008, at 1:44 PM, David Pearce wrote:

> Hi Terence,
>
>> Yes.  you must use
>>> list : '(' listBody ')' -> ^(LIST listBody?)
>> not
>>> list : '(' listBody ')' -> ^(LIST listBody)
>> clearly listBody can be optional, right?
>
> Yes, in this case it is definitely optional.  But, in the Java  
> grammar case it is not:

Notice the ? is in the tree construction not the matching.

>> classDeclaration
>>    :    'class' Identifier (typeParameters)?
>>        ('extends' type)?         ('implements' typeList)?
>>        classBody
>>    ;
>> ...
>> classBody
>>    :    '{' classBodyDeclaration* '}'
>>    ;
>> ...
>> classBodyDeclaration
>>    :    ';'
>>    |    ... [other productions]
>>    ;

I don't understand the issue.  Don't alter the matching, just add ? to  
the ast constr.
Ter


More information about the antlr-interest mailing list