[antlr-interest] ANTLR: tree nodes access

Antonio Tancredi nazareno.tancredi at gmail.com
Fri Nov 23 01:06:31 PST 2012


Yes, I think it's better to create my AST using semantic actions.
Thanks Juancarlo.

Antonio Tancredi

2012/11/22 Juancarlo Añez <apalala at gmail.com>

> Antonio,
>
> You don't have to use ANTLR's AST construction. You can return your own
> class instances from semantic actions at the end of each rule.
>
> OTOH, what I did on a recent project was to post-process ASTs to create a
> more "intelligent" hierarchy.
>
>
> On Wed, Nov 21, 2012 at 12:55 PM, Antonio Tancredi <
> nazareno.tancredi at gmail.com> wrote:
>
>> Hi,
>> I need some help about a little problem. Here you can find a description:
>>
>> http://stackoverflow.com/questions/13490897/antlr-tree-nodes-access
>>
>> Sorry for the cross-ask, but I found this mailing list and I thought that
>> this can be a better place to ask a question like that.
>> The problem is: I want to create a class field for each child of the tree.
>> The binary tree example is the simplest one.
>> Maybe this example is more interesting:
>>
>> def
>> : nameIdent=IDENT EQ element SEMI -> ^(NODE_DEF $nameIdent element)
>> | nameIdent=IDENT EXTENDS extIdent=IDENT EQ element SEMI -> ^(NODE_DEF
>> $nameIdent EXTENDS_IDENT[$extIdent] element)
>> ;
>>
>> where IDENT is an identifier, EQ is '=', SEMI is ';', EXTENDS is
>> 'extends'.
>>
>> This kind of extension is simple: A extends B. Anyway, the things can be
>> more difficult, just think about java and the keywords extends/implement.
>> What I want to do is to set a field inside my tree class with the value of
>> the child, not just add it the the "children" array.
>>
>> Do you have any suggestion? Thanks.
>>
>>
>> Antonio Tancredi
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>
>
>
> --
> Juancarlo *Añez*
>


More information about the antlr-interest mailing list