[antlr-interest] ast problem

Koen Segers KoenSegers at scarlet.be
Thu Mar 10 09:02:38 PST 2005


I will explain it totally...

I created an ast in my Parser.
This parser is optimized in TreeParser.
I analyze the ast and replace a part of the tree with new objects.
These object have a sort of execute and generate methods.

typeDef
        :       
                #(ASTtypeDef
                        {
                                Type type = new Type();
                                boolean constant = false;
                        }
                        #(ASTdeclarationSpecifiers
                                (CONST {constant = true;} )*
                                (INT
                                        {
                                                type = new Int();
                                        }
                                )
                                {type.setConstant(constant);}
                        )

                        #!(ASTinitDeclaratorList
                                (i:ID           //something else than ids??
                                        {
                                                Typedef typedef = new 
Typedef(type, i.getText());
                                                //symbol table
                                                //tree construction
                                                #i.setAbstractAst(typedef);
                                                ## = #(##, #i);
                                        }
                                )*
                        )
                )

as you can see the ASTinitDeclaratorList can be several ID's.
These ID's must will be the the new nodes... (instead of 1 typedef node)

On Thursday 10 March 2005 11:43, Bryan Ewbank wrote:
> We need more information.  What is the root node to be, since it is
> not the typedef?
>
> If you have something like this:
>    statement
>
>       : ...
>       :
>       | TYPEDEF^ a:name b:type
>
>       ;
>
> Then a and b are children of the same node - the TYPEDEF node.  So,
> you can overwrite the name and type of that root node if you want, or
> you can leave it.
>
> The sequence you want is probably
>       #( #[TYPE,"NAME"], #a, #b );
> but you already have that - with the TYPEDEF as the root of this small
> tree.
>
> Hope this helps,
> - B
>
> On Thu, 10 Mar 2005 10:37:31 +0100, Koen Segers <koensegers at scarlet.be> 
wrote:
> > I want to remove an astnode typedef with childeren a and b, and
> > insert the a and b node. How do I do this?
> >
> >   ##=#(null,#i); //gives only b (a removed)
> >   ##=#(##,#i);    //gives a as child of b.
> >
> > I just want a and b to be childeren of the same root.

-- 

Koen Segers

<koensegers at scarlet.be>
<http://eddyvite.dyndns.org>


More information about the antlr-interest mailing list