[antlr-interest] Duplicate members when generating code with 2 import levels in Java with ANTLR-3.1.1

Jim Idle jimi at temporal-wave.com
Mon Oct 27 14:46:02 PDT 2008


On Mon, 2008-10-27 at 22:30 +0100, Laurent Caillette wrote:

> Hi all,
> 
> Here is a composite grammar C which imports parser P2 which imports parser P1:
> 
> - - - - - - - - - - - - - - - - - -
> lexer grammar L ;
> 
> LETTER : 'a'..'z' ;
> SPACE : ' ' ;
> 
> - - - - - - - - - - - - - - - - - -
> parser grammer P1 ;
> 
> letter : LETTER ;
> spaces : SPACE+ ;
> 
> - - - - - - - - - - - - - - - - - -
> parser grammer P2 ;
> import P1 ;
> 
> letters : letter+ ;
> 
> - - - - - - - - - - - - - - - - - -
> grammar C ;
> import L, P1, P2 ;


You import P1 here and then in P2 you import P1 again, hence there are
two instances of P1 created and this is not allowed. Either do not
import P1 in P2, or just import P2 in C.

Jim

> 
> stuff : ( letters spaces )+ ;
> 
> - - - - - - - - - - - - - - - - - -
> 
> 
> Generating code with ANTLR-3.1.1 I get this in CParser.java:
> 
>     // delegates
>     public C_P1 gP1;
>     public C_P2_P1 gP1;

Tough of seemingly different type, they are both gP1.



>     public C_P2 gP2;
> 
> Ooops ! gP1 appears twice and causes compilation errors.
> 
> Regards,
> 
> c.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081027/bbc64582/attachment.html 


More information about the antlr-interest mailing list