[antlr-interest] Best place to modify AST?

Cameron Esfahani dirty at apple.com
Fri Jul 6 13:16:00 PDT 2007


My JSON-derived grammar supports assigning JSON entities to  
variables.  These variables can then be used in other JSON entities  
to refer to the original entities:

foo = { "tag" : "value" }

{ "child" : foo }

As far as any consumer of the final tree is concerned, they shouldn't  
see this.  When they iterate through the tree, I want it to appear,  
for all intents and purposes, that the above input looks like:

{ "child" : { "tag" : "value" }

I'm trying to decide the best place to handle this.  My initial idea  
is to have two separate tree walker stages, the first would resolve  
any of these references and update the AST, and the second would  
process this updated tree.

Is this an appropriate route to take?  Can a tree walker change the  
underlying as it's, uh, walking it?

Cameron Esfahani
dirty at apple.com

"With or without religion, good people can behave well and bad people  
can do evil; but for good people to do evil - that takes religion."

Steven Weinberg



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070706/d9c97802/attachment.html 


More information about the antlr-interest mailing list