[antlr-interest] rule parameter question

Bart Kiers bkiers at gmail.com
Thu Jun 30 06:21:52 PDT 2011


Just for the record, in case someone stumbles upon this post, the answer
from SO:

-------------------------------------------------------------------------

If you don't explicitly specify the tree to be used in your grammar,
.tree (which
is short forgetTree()) will return a java.lang.Object and a CommonTree will
be used as default Treeimplementation. To avoid casting, set the type of
tree in your options { ... } section:

options
{
    output=AST;
    ASTLabelType=CommonTree;
}



On Thu, Jun 30, 2011 at 3:20 PM, Bart Kiers <bkiers at gmail.com> wrote:

> No problem: SO _does_ work with notifications, but they only go out once a
> day or so by default.
>
> Good to hear it worked.
>
> Regards,
>
> Bart.
>
>
> On Thu, Jun 30, 2011 at 3:16 PM, Mark Truluck <mark.truluck at cogiton.com>wrote:
>
>>
>> Hi Bart – sorry – thought I'd get an email from them.
>>
>> That worked perfectly – thanks very much.
>>
>> Mark
>>
>>  From: Bart Kiers <bkiers at gmail.com>
>> Date: Thu, 30 Jun 2011 14:42:53 +0200
>> To: Mark Truluck <mark.truluck at cogiton.com>
>> Cc: "antlr-interest at antlr.org interest" <antlr-interest at antlr.org>
>> Subject: Re: [antlr-interest] rule parameter question
>>
>> Hi Mark,
>>
>> I presume you didn't see my answer on Stackoverflow:
>>
>> http://stackoverflow.com/questions/6529359/how-to-pass-commontree-parameter-to-an-antlr-rule
>> ?
>>
>> If you did, is there anything that wasn't clear?
>>
>> Regards,
>>
>> Bart.
>>
>>
>> On Thu, Jun 30, 2011 at 2:26 PM, Mark Truluck <mark.truluck at cogiton.com>wrote:
>>
>>> Hello,
>>>
>>> I am trying to do what I think is a simple parameter passing to a rule in
>>> Antlr 3.3:
>>>
>>> -----------
>>> grammar rule_params;
>>>
>>>
>>> options
>>> {
>>>    output = AST;
>>> }
>>>
>>> rule_params
>>>    :   outer;
>>>
>>>
>>> outer:  outer_id '[' inner[$outer_id.tree] ']';
>>>
>>> inner[CommonTree parent]    :   inner_id '['  ']';
>>>
>>>
>>> outer_id    : '#'! ID;
>>>
>>> inner_id    : '$'! ID ;
>>>
>>>
>>> ID   :  ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9' | '_' )* ;
>>>
>>> ---------
>>>
>>> However the inner[CommonTree parent] generates the following:
>>>
>>> *** inner4=inner((outer_id2!=null?((Object)outer_id2.tree):null));
>>>
>>>
>>> Resulting in this error:
>>>
>>> *** The method inner(CommonTree) in the type rule_paramsParser is not
>>> applicable for the arguments (Object)
>>>
>>>
>>> As best I can tell, this is the exact same as the example in the Antrl
>>> book:
>>>
>>>
>>> classDefinition[CommonTree mod]
>>>
>>> (Kindle Location 3993) - sorry I don't know the page number but it is
>>>  in the middle of the book in chapter 9, section labeled "Creating Nodes
>>>  with Arbitrary Actions".
>>>
>>> Thanks for any help.
>>>
>>>
>>>
>>> Mark Truluck
>>> COGITON, Inc.
>>>
>>>
>>>
>>>
>>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>>> Unsubscribe:
>>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>>
>>
>>
>


More information about the antlr-interest mailing list