[antlr-interest] Re: nice threads

lgcraymer lgc at mail1.jpl.nasa.gov
Fri Jun 14 15:04:52 PDT 2002


--- In antlr-interest at y..., Brian Smith <brian-l-smith at u...> wrote:

> But, I believe I mis-stated the SableCC technique. They generate a 
set 
> of classes that represent the AST, _and_ they generate a "visitor" 
> abstract class. The "visitor" is the basic implementation of the 
visitor 
> pattern. Basically, each pass subclasses the visitor abstract class 
and 
> overrides the appropriate methods.
> 
> I am doing something similar to SableCC, but instead of operating on 
> grammars I am operating on Abstract Syntax Graphs in the form of MOF 
> models (MOF is a subset of UML used to model the static-semantics/ 
> abstract-syntax of modeling and programming languages). That is, I 
> generate a visitor from the abstract syntax's UML diagram, and I 
call 
> this visitor while walking the composition associations in the 
diagram.
> 

Brian--

The Visitor pattern works well if you want to generic processing (call 
foo() at each node of type FOO), but it is less capable than a tree 
walker which can assign actions according to matched patterns and not 
just matched nodes.  There are some cases where a Visitor is to be 
preferred to a tree walker, and some where a mix is appropriate--visit 
all nodes of a tree, but if you encounter a node of type FIXME then 
use a tree walker on it and its children instead of visiting them.

Automatic tree grammar generation is in the process of being added to 
ANTLR--I've implemented it and a rewrite syntax, have gotten basic 
permission for release, but still have to find out what copyright 
blurb to add to the files and find out if it can be released through 
the antlr.org site or if I have to release it through an open source 
site that NASA has a contract with.

In fact, if you substitute "tree walker" for "Visitor" in what you are 
saying, then you are right in line with the "old guard" who have been 
actively using trees since Ter invented SORCERER.  If you poke around, 
you'll find old posts from Ter, Monty, John Mitchell, and others who 
advocate having actions in tree walkers for code generation, but to 
avoid them in parsers except to do such things as symbol table 
construction.  Tree manipulation is a very powerful tool for 
source-to-source translation.

--Loring


 

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



More information about the antlr-interest mailing list