[antlr-interest] Inheritance problem

Bharath Sundararaman Bharath.Sundararaman at starthis.com
Mon Apr 4 14:37:36 PDT 2005


Hi Bob,

I had a similar problem too, with grammar inheritance. I am using the
ANTLR plug-in for Eclipse and if you are using ANTLR on Eclipse, I
suggest that you right-click on your grammar file -> properties and
browse for the super grammar. It worked right away, for me.

Good luck.

Bharath.

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Bob Temporary
Sent: Monday, April 04, 2005 3:38 PM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Inheritance problem

Greetings,
I'm having a problem with the inheritance in ANTLR. I am working on a
series of parsers that are based off one another. In order to
implement some additional features, I created a subclass of
antlr.LLkParser that my first parser extends. The next parser must
also extend my subclass, but also inherit all of the grammar from the
first parser. So my setup basically looks like this:


GenericParser.java:
public abstract class GenericParser extends antlr.LLkParser ...
...


Parser1.g:
class Parser1 extends Parser( "com.myparser.GenericParser" );
...

Parser2.g:
class Parser2 extends Parser1( "com.myparser.GenericParser" );



Parser1 works fine, but the expandedParser2.g file that's generated is
wrong. The parser definition line looks like this:
class Parser2 extends ( "com.embarcadero.sqlparsers.GenericParser" );

Of course, I get an error because that's not valid syntax. If I try to
leave the ("com...") stuff off in parser2.g, then it's base class is
just antlr.LLkParser, which is wrong.

How do I accomplish this?


More information about the antlr-interest mailing list