[antlr-interest] Duplicate members when generating code with 2 import levels in Java with ANTLR-3.1.1
Loring Craymer
lgcraymer at yahoo.com
Mon Oct 27 17:43:57 PDT 2008
Gavin--
I think that your analogy is way off. The ANTLR 3 composition looks much more like Python's "import module" than it does OO inheritance. In an OO setting, A inheriting from B2, B3 with B2 and B3 each inheriting from C has the problem that data duplication is either essential or a big problem; ANTLR composites can safely avoid that (at least, for the most part).
--Loring
----- Original Message ----
> From: Gavin Lambert <antlr at mirality.co.nz>
> To: Loring Craymer <lgcraymer at yah oo.com>; Terence Parr <parrt at cs.usfca.edu>; Laurent Caillette <laurent.caillette at gmail.com>
> Cc: antlr-interest Interest <antlr-interest at antlr.org>
> Sent: Monday, October 27, 2008 5:05:28 PM
> Subject: Re: [antlr-interest] Duplicate members when generating code with 2 import levels in Java with ANTLR-3.1.1
>
> At 12:04 28/10/2008, Loring Craymer wrote:
> >Just my 2 cents, but shouldn't duplicate imports be supported at
>
> >the language level, as is true for Java, C#, and even C/C++ with
>
> >the usual #ifdef wrapping? It seems to me that leaving
> dependency
> >management to the user limits the convenience of composition.
>
> If you think of grammar imports as class inheritance (which is
> what they behave most like), then I think you'll find that those
> other languages don't really support it all that well either :)
>
> In C#, multiple inheritance of interfaces is supported cleanly,
> but interfaces carry no implementation. Since the
> implementation-inheritance model is single-inheritance, there's no
> possibility of a serious clash. I'm not sure about Java exactly,
> but I believe it's similar.
>
> In C++, if you try to make class C inherit from both B1 and B2
> (where B2 inherits from B1), then it will indeed include an extra
> copy of B1 (in what's known as a "deadly diamond"), unless B1 is a
> virtual base class. This seems like the same behaviour as what
> ANTLR exhibits, except that (currently at least) ANTLR provides no
> means to make it a virtual base :)
More information about the antlr-interest
mailing list