[antlr-interest] constructor in a Parser Class

Tarun Khanna tarunkhanna at gmail.com
Tue Jul 26 12:40:52 PDT 2005


hey thanks,

well I did something similar. I created my constructor and from within it 
called the default constructor using "this" and then did my own 
initialization after that.

Thanks again
Tarun

On 7/26/05, Prashant Deva <prashant.deva at gmail.com> wrote:
> 
> Tarun,
> dont use the noConstructor=true option. Do as i told you in my last mail.
> Inheirt a class and from the parser class and override the constructors.
> 
> PRASHANT
> 
> On 7/26/05, Tarun Khanna <tarunkhanna at gmail.com> wrote:
> > Thanks a lot for your help.
> >
> > If we use the noConstructor=true option won't we have to do all the
> > initialization ourselves? Aren't there any initializations that are done
> > generated by the automatically generated code, that I may ignore (or I 
> am
> > not even supposed to know as it is automatically generated). For eg. the
> > _tokenNames array of token names. This is something that is initialized 
> in
> > the automatically generated constructor. I guess a user is not even 
> supposed
> > to know of the existence of such an array.
> >
> > Thanks
> > Tarun
> >
> >
> > On 7/25/05, Prashant Deva <prashant.deva at gmail.com> wrote:
> > > You can use the anonymous no-static initialization.
> > > Eg-
> > > class MyClass(){
> > >
> > >
> > > {
> > > // do initialization
> > > }
> > >
> > > public MyClass() {}
> > >
> > > }
> > >
> > >
> > > Or you can even make a class inherit from the generated parser class
> > > and do the initialization in its constructor.
> > >
> > > PRASHANT
> > >
> > > On 7/25/05, Tarun Khanna <tarunkhanna at gmail.com> wrote:
> > > > If have some private variables to initialize, how do we specify 
> these
> > > > initializations in a constructor. If I try to write a constructor, 
> the
> > > > compiler complains..
> > > >
> > > > I noticed the generated code contains constructors that do some 
> stuff.
> > I
> > > > would want these constructors to additionally initialize some of my
> > > > variables. How can that be done.
> > > >
> > > >
> > > > Thanks
> > > > --
> > > > Tarun Khanna
> > >
> >
> >
> >
> > --
> > Tarun Khanna
> 



-- 
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050726/79190439/attachment.html


More information about the antlr-interest mailing list