[antlr-interest] Re: Translators Should Use Tree Grammars

lgcraymer lgc at mail1.jpl.nasa.gov
Mon Nov 22 23:41:08 PST 2004



--- In antlr-interest at yahoogroups.com, Monty Zukowski <monty at c...> wrote:
> On Nov 22, 2004, at 7:21 PM, lgcraymer wrote:
> 
> >
> > No, I haven't added anything special for pattern matching.  The
> > automated tree grammar generation lessens the need--it provides the
> > interactive feedback needed to deal with tree transformation as a
> > design problem, not just to construct trees that can be walked via a
> > tree grammar.  That makes ANTLR's context-dependent pattern matching
> > more powerful, and the context-independent findAll routines
> > essentially irrelevant.
> >
> 
> OK, to be more concrete here, I want to give an example and then try 
> and figure out the definitions:
> 
> 1)  Add code to the entry and exit of every function.
>   2)  Add code to the entry and exit of all functions which have struct 
> special_thing as an argument which return ints.
>
> So there's patterns as in grammatical structure to find the function 
> definitions as in 1), and there are patterns to match specific 
> incarnations of trees within that structure as in 2).  I need help with 
> clear descriptions of these, but currently ANTLR's support of 2) is 
> left to actions and/or semantic predicates which can be ugly.

Ok, tree construction predicates might help some with case 2, but this
is a case where you need to a.)  identify function declaration syntax,
b.) record argument and return value semantics, and c.) take action
that depends on recognizing these specific semantic elements.

Assuming that you do not have explicit return types here (otherwise
this is trivial) then a-c translate to:
a.)  whether or not function declaration syntax is unambiguous at the
parser level, build trees for which function declarations are
unambiguously recognized.
b.)  record return semantics either as an attribute (field) of the
function declaration root node or by inserting a return type subtree
during one treewalk pass.  Argument syntax/semantics is presumably
already available before walking the function body; if not, reorganize
the tree to achieve that.
c.)  Having recorded the semantic information where it can be
accessed, carry out the statement insertions either in a subsequent
tree transforming pass or in a code generation pass.

This is not a bad example.  a) is one or more passes to consolidate
syntactic information into a usable tree form, b.) is a semantic
analysis pass, and c.) is a pass to express semantic information into
syntactic form.

--Loring

> 
> 
> Monty
> 
> ANTLR & Java Consultant -- http://www.codetransform.com
> ANSI C/GCC transformation toolkit -- 
> http://www.codetransform.com/gcc.html
> Embrace the Decay -- http://www.codetransform.com/EmbraceDecay.html





 
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