[antlr-interest] RE: Is there a way to pass parameters to rules?

Ken Cecka ceckak at alumni.washington.edu
Fri Dec 23 18:26:06 PST 2005


Perfect - thanks!

Scott Stanchfield wrote:

> Sure:
> 
> targetRule [String foo, Person p]
> :     ...
> ;
> 
> callingRule
> { Person p = new Person(); }
> :     targetRule["blah blah", p]
> ;
> 
> -- Scott
> 
> 
>> -----Original Message-----
>> From: antlr-interest-bounces at antlr.org
>> [mailto:antlr-interest-bounces at antlr.org]
>> [On Behalf Of Ken
>> and Timi Cecka
>> Sent: Friday, December 23, 2005 7:31 PM
>> To: antlr-interest at antlr.org
>> Subject: [antlr-interest] Is there a way to pass parameters to rules?
>> 
>> Hi All,
>> 
>> I know rules can return a value with the 'returns' keyword,
>> but is there any way to pass a value to a rule when it's invoked?
>> 
>> In developing my treeparser, I'm repeatedly finding that I
>> want a rule to simply modify the object being constructed by
>> the caller, and it's not always easy or convenient to
>> construct a return type that temporarily encapsulates the
>> results of the rule so that they can be passed up.  It would
>> be much simpler of the caller could pass a pointer down and
>> allow the rule to modify the object directly.
>> 
>> Ken
>>




More information about the antlr-interest mailing list