[antlr-interest] TreeParser transform examples

Michael Brade brade at informatik.uni-muenchen.de
Tue Mar 14 07:38:42 PST 2006


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 

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),
                      ##.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.


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 --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20060314/61695d31/attachment.bin

More information about the antlr-interest mailing list