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


Hi Roger,

How many people out there are interested in seeing support for attribute
grammars? I know this topic has been raised before
it's just that automatically inheriting/synthesizing attributes such as
type and value throughout the tree saves a LOT of code.

I can see some benefits in having attributes (or just attribute placeholders) generated automatically for particular nodes, but on the other hand, I can also see why Etienne wants to keep the grammar as clean and as simple as possible.

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. Just briefly: for the project I am working
on ATM I have written a simple grammar for defining attributes. This
grammar generates a tree walker that does all the work for you.

Here is an example snippet:
         name: String;
         type: String;
         size: Integer;

     /* attributes for a PVariableDeclaration: type, size */
     AVariableDeclaration: type[syn:TypeSpecifier], size[syn:TypeSpecifier];

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 */ }

All the nodes are expected to have attributes?

One can create appropriate hashtables, or even a single hashtable with an instance of Properties for each or some of the nodes by hand, or automatically as your example shows. It is up to a particular application to decide what is best suited for it.
I like your example, but it sort of feels a bit too restrictive to be included as a standard into the SableCC, but I can see some potential in here ;o) Need to think it over a bit I guess...