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:

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

I can't make classBody here optional, like e.g.:

 > classDeclaration
 >     :    'class' Identifier (typeParameters)?
 >         ('extends' type)?         ('implements' typeList)?
 >         classBody?
 >         -> ^(Class ...)
 >     ;

Otherwise, I'm accepting Java files which are not correct.  It seems the 
only option is to refactor giving this:

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

But, this doesn't seem ideal to me?

Cheers,

Dave

>>> This seems clumsy, since neither the X or Y tokens are actually needed
> 
> just use ? :)
> 
> Ter
> 

-- 
Lecturer in Computer Science,
School of Mathematics, Statistics and Computer Science,
Victoria University of Wellington,
PO Box 600,
Wellington,
New Zealand.

Office: Cotton 231
Telephone: +64 (0)4 463 5833
URL: http://www.mcs.vuw.ac.nz/~djp

List: http://www.antlr.org:8080/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org:8080/mailman/options/antlr-interest/your-email-address


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to