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