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

Laurent Caillette laurent.caillette at gmail.com
Mon Oct 27 15:56:41 PDT 2008


Ok, thanks a lot. I was not fully aware of how imports were resolved.

Terence, the sample I suggested is wrong, C should not import P1.
http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars#CompositeGrammars-Legalimports

I suggest to add a few words at the end of the introduction to explain
this behavior. Could be:
<<
[There is no need to copy any rules from the delegate grammars into
the root grammar.]
Because of this "whiteboard" approach, each grammar should be imported
only once. If B relies on rules in A, it should not import A if R
already imports B. Otherwise it would cause some duplicate members in
generated code.
>>

Regards,

c.

http://novelang.sf.net


On Mon, Oct 27, 2008 at 10:34 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
> You are importing a grammar more than once into C.  probably not what you
> want; the error is correct I guess.


On Mon, Oct 27, 2008 at 10:46 PM, Jim Idle <jimi at temporal-wave.com> wrote:
> 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


More information about the antlr-interest mailing list