[antlr-interest] TreeParser transform examples

Jose Ventura jose.ventura.roda at gmail.com
Tue Mar 14 08:31:39 PST 2006


If I understand you, you want add STRING AST in OPERATORS.
I don't test this code, but you can try anything also:

structured_term!:
                 * {AST aux=null;}*
                   #(NS_LABEL #(PREFIX prefix:NCNAME)
                            #(LOCAL   label:NCNAME)
                   {
                     ## = #([OPERATORS,"operators"],
                              #([TYPE_SEL,"type"], [STRING,"tree"]),
                              #([NAMESPACE_SEL,"namespace"], prefix),
                              #([LABEL_SEL,"label"], label),
                           );
                    * aux=##;
*                   }
                   t:children
                   {
*                      aux.addChild (#([STRING,"TEST-NODE"]));
*                   }
                  )
               ;

Regards,
José Ventura

2006/3/14, Michael Brade <brade at informatik.uni-muenchen.de>:
>
> Hi,
>
> I'm having quite some trouble building a tree parser that outputs another
> and
> thus has buildAST=true set. I did not find any examples that are extensive
> and that do that. Any ideas? The Calc example shipped with antlr is far
> too
> simple.
>
> One question I cannot figure out for instance: how do I add more children
> to
> the output AST being generated by a rule in another action?
>
> This does not work:
>
> structured_term!: #(NS_LABEL #(PREFIX prefix:NCNAME)
>                             #(LOCAL   label:NCNAME)
>                    {
>                      ## = #([OPERATORS,"operators"],
>                               #([TYPE_SEL,"type"], [STRING,"tree"]),
>                               #([NAMESPACE_SEL,"namespace"], prefix),
>                               #([LABEL_SEL,"label"], label),
>                            );
>                    }
>                    t:children
>                    {
>                      ##.addChild( #([STRING,"TEST-NODE"]) );  // NOPE!!!
> :(
>                    }
>                   )
>                ;
>
> The addChild call puts a
> structured_term_AST = (AST)currentAST.root;
> in the generated code right before the addChild call and spoils all the
> fun.
>
> Hints?
>
> Thanks,
> --
> Michael Brade;                 KDE Developer, Student of Computer Science
> |-mail: echo brade !#|tr -d "c oh"|s\e\d 's/e/\@/2;s/$/.org/;s/bra/k/2'
> °--web: http://www.kde.org/people/michaelb.html
>
> KDE 4: Beyond Your Expectations
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060314/cc234ed2/attachment.html


More information about the antlr-interest mailing list