[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Grammar inheritance, attributes and framework desing ideas [Was: Re: [wishlist] Attributes]



I think if you bring in inheritance, you might want to address the more
general problem of grammar reuse. Just as with aspects, one cross-cut is
common attributes as Roger mentions. Inheriting to compose "dialects"
with common rules and specialization is another. But a third not yet
brought up is composition, where you embed a mini-grammar inside another
(Javadoc tag grammar, for instance). I might like to define a grammar
that pertains to just a particular state, e.g. "doc_comment" and perhaps
re-use this, but it's not an is-a relationship, so inheritance isn't the
right representation. You might declare it this way:

States
    doc_comment : #import "javadoc.grammar"

And putting it together, you might have a Java grammar which imports a
javadoc grammar that in turn might have dialects to allow for
doclets/extensions. I'm sure attributes could fit in there too. ;-)

Right now I'm facing adding yet more productions to support XPIDL in my
IDL grammar (dialect) and also to support doc-comments from XPIDL
(composition, since you could re-use a javadoc module), so the subject
of reuse and simplification/encapsulation of grammars has been on my
mind.

--kd

> 
> Roger Keays wrote:
> > How many people out there are interested in seeing support for 
> > attribute grammars?
>  > ...
> > Etienne doesn't want to have attributes on the SableCC 
> generated nodes 
> > and suggests storing them in a hashtable. I think you can still do 
> > this with an attributed grammar.
>  > ...
> > Here is an example snippet:
> >     Attributes
> >         name: String;
> >         type: String;
> >         size: Integer;
> >...
> > The walker generated contains three hashtable (name, type, 
> size) indexed
> > by SableCC nodes and provides getter methods. e.g.
> > 
> >     if (attributes.getType(node).equals("char")) { /* do 
> something */ 
> > }
> > 
> > Thoughts? Comments?
> 
> Since the recent thread discussing grammar inheritance, I 
> have been thinking seriously about the subject, and my 
> initial desing for them includes something that resembles 
> what Roger is suggesting.
> 
> So, I see some extentions to SableCC that would satisfy my 
> worries about code maintenance and be in line with the needs 
> for attributes often voiced on this mailing-list.
> 
> So, these propositions should be added to the wish-list, as I 
> will need to devote more time thinking about many details, 
> including implementation related ones, and how it will all 
> integrate within the
> CST->AST extentions.
> 
> I saw a paper presentation about Polyglot at CC 2003 this 
> last week, and this work does contain interesting ideas.  
> Some of these ideas could make a nice addition for SableCC, 
> but they should first be adapted as the constraints are 
> different.  (See Patrick Lam's last message for URLs).
> 
> I will discuss my ideas on this list once the CST->AST stuff 
> will have migrated to a stable version.
> 
> Have fun!
> 
> Etienne
> -- 
> Etienne M. Gagnon, Ph.D.             http://www.info.uqam.ca/~egagnon/
> SableVM:                                       http://www.sablevm.org/
> SableCC:                                       http://www.sablecc.org/
>