[antlr-interest] Passing extra arguments to constructor?
Scott Stanchfield
scott at javadude.com
Mon Jul 31 05:36:23 PDT 2006
It's easier to create instance variables and setter methods in the parser:
header {
...
}
class MyParser extends Parser;
{
private SomeType someVariable_;
public void setSomeVariable(SomeType someVariable) {
someVariable_ = someVariable;
}
}
rule1:
...
Then after you create the parser instance, and before you trigger the
top-level rule, just set the values you need.
(You should be able to do this in most other OO target languages as well,
though I've only used ANTLR for Java)
-- Scott
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of O.E. Dragon
> Sent: Monday, July 31, 2006 8:02 AM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Passing extra arguments to constructor?
>
> On Mon, 31 Jul 2006 12:35:20 +0200
> "Peter Palotas" <peter.palotas at gmail.com> wrote:
> > I was wondering if it is possible to specify additional
> arguments to
> > pass to the generated Parser's constructor and how this should be
> done?
>
> Hi,
>
> In Java, you could create a subclass to the Parser class
> generated by ANTLR. This class would have the contructors you
> want and would call
> super(...) with the generated Parser's usual arguments. I
> presume you could do something similar in C#, C++ or Python
> as those are all OO languages, but I have no experience with them.
>
> Cheers,
> -Olivier
>
More information about the antlr-interest
mailing list