[antlr-interest] Re: Constructors

pete_forman pete.forman at westerngeco.com
Mon Jul 8 03:02:50 PDT 2002


--- In antlr-interest at y..., Ric Klaren <klaren at c...> wrote:
> On Sun, Jun 09, 2002 at 09:50:51PM -0000, johnclarke72 wrote:
> > I know how to define extra methods within my grammar but how can I 
> > write my own Constructors within a grammar. Essentially I want to add 
> > two constructors (one that has no parameters and another that has 
> > parameters).
> 
> Just add them:
> 
> header { // headerstuff }
> 
> { // for c++ this goes into the generated .cpp file
> // extra constructor implementation
> MyParser::MyParser( .. .. .. )
> {
> }
> 
> }
> class MyParser extends Parser;
> {
> // for java the implementation goes here as well (i think)
> MyParser( .. .. .. .. );
> 
> }

This fails for me (2.7.1 generating Java).  There already is a
contructor with no arguments in the generated code, so my
constructor gets a duplicate definition error when I compile.

There does not seem to be a way to augment the constructors
generated by ANTLR.  I suppose that I could subclass from the 
generated code.  Another workaround might be to add an init
method but that seems an unnecessary burden on the clients.
-- 
Pete Forman                -./\.-  Disclaimer: This post is originated
WesternGeco                  -./\.-   by myself and does not represent
pete.forman at westerngeco.com    -./\.-   opinion of Schlumberger, Baker
http://petef.port5.com           -./\.-   Hughes or their divisions.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list