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

[no subject]



Gecko/20030327 Debian/1.3-4
X-Accept-Language: en
MIME-Version: 1.0
To: sablecc-list@sable.mcgill.ca
Subject: [wishlist] Attributes
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Sender: owner-sablecc-list@sable.mcgill.ca
Precedence: bulk

Hi all,

How many people out there are interested in seeing support for attribute
grammars? I know this topic has been raised before
(http://www.sable.mcgill.ca/listarchives/sablecc-list/msg00368.html)...
it's just that automatically inheriting/synthesizing attributes such as
type and value throughout the tree saves a LOT of code.

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:
     Attributes
         name: String;
         type: String;
         size: Integer;

     /* attributes for a PVariableDeclaration: type, size */
     AVariableDeclaration: type[syn:TypeSpecifier], size[syn:TypeSpecifier];
     AIdentifierVariableDeclaration:
type[<?node.getIdentifier().getText()?>];;

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?

Roger


.


-- 
Etienne M. Gagnon, Ph.D.                             egagnon@j-meg.com
President                                      http://www.sablevm.org/
J-Meg inc.                                     http://www.sablecc.org/