Re: parent pointers in AST nodes

Quinn Tyler Jackson <quinn_jackson2004@yahoo.ca>
Tue, 1 Dec 2009 13:52:06 -0800

          From comp.compilers

Related articles
[2 earlier articles]
Re: parent pointers in AST nodes zaimoni@zaimoni.com (Kenneth 'Bessarion' Boyd) (2009-11-27)
Re: parent pointers in AST nodes idbaxter@semdesigns.com (Ira Baxter) (2009-11-27)
Re: parent pointers in AST nodes DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-11-28)
Re: parent pointers in AST nodes bartc@freeuk.com (bartc) (2009-11-30)
Re: parent pointers in AST nodes torbenm@diku.dk (2009-11-30)
Re: parent pointers in AST nodes kkylheku@gmail.com (Kaz Kylheku) (2009-12-01)
Re: parent pointers in AST nodes quinn_jackson2004@yahoo.ca (Quinn Tyler Jackson) (2009-12-01)
Re: parent pointers in AST nodes mwso@earthlink.net (Gary Oblock) (2009-12-14)
| List of all articles for this month |
From: Quinn Tyler Jackson <quinn_jackson2004@yahoo.ca>
Newsgroups: comp.compilers
Date: Tue, 1 Dec 2009 13:52:06 -0800
Organization: Compilers Central
References: 09-11-060 09-11-067
Keywords: AST
Posted-Date: 01 Dec 2009 17:50:52 EST

Torben said:


> I find the visitor pattern non-intuitive for AST processing. A set of
> mutually recursive functions (one for each syntactic category, i.e., one
> for expressions, one for statements etc.) that each do case analysis
> over the node type and calls recursively on children nodes is much more
> intuitive.


For my own work with post-parse trees (AST or otherwise), I find that
a single visitor with registered node-type passengers proves to be the
most efficient. This allows for a simultaneous (for some value of
"simultaneous") top-down, bottom up, breadth-first/last pass, with
each passenger, and reduces overall processing time accordingly. It
does, however, require passengers to be registered in the right order
if visitation order dependencies are important and is especially
opaque if a passenger actually modifies the tree during its visit to a
node.


But overall, "it works here."


Quinn



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.