[antlr-interest] Transforming AST subtrees in TreeParser with "buildAST = false"

Ric Klaren klaren at cs.utwente.nl
Wed May 19 08:19:03 PDT 2004


On Wed, May 19, 2004 at 02:45:52PM -0000, micheal_jor wrote:
> Is this possible?

To some extent it should work I guess. (I'm btw also in a kindoff similar
situation where I only want to do some minor patching in a previously
generated tree. I'm not that familiar with tree transformations but it
feels a bit cumbersome atm)

> I am using a TreeParser but with buildAST=false to avoid redundant
> "copying" of most of the nodes in the AST. They are untouched by the
> minor transformations.
>
> I guess I have two questions really:
>
> 1. In a TreeParser, is it possible to specify that "buildAST=true"
> only for certain rules or rule-Alternatives. The rest of the AST is
> left as is (it is "copied" to output logically but no *actual* copying
> is done).

buildAST is a grammar option so no go there... Doing it inverted will work
e.g. turn on construction and disable construction for all rules except the
ones where you want it.

> 2. Failing (1), is it "safe" (advisable?) to include tree tranforming
> statements in the action code of TreeParsers with buildAST=false. I am
> aware that the tree construction/transformation shortcut notation
> would be unavailable in this case.

You can always use tree construction syntax in whatever place of the target
code (AFAIK) You only have to do some stuff manually since it's not done
due to buildAST=false. Also you have to be very carefull when changing the
AST because the current rule is operating on it still. (e.g. you may be
building something that is easy to break) Also be very carefull in using
the standard AST/ASTFactory's methods for changing tree parts, the names
hide a lot of things that happen under the hood...

I guess you could come a long way with playing a bit with a toy grammar and
the options and see what happens in the generated code.

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
 "Don't call me stupid." "Oh, right. To call you stupid would be an insult
    to stupid people. I've known sheep that could outwit you! I've worn
              dresses with higher IQs!" --- A Fish Called Wanda



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list