You are here: Home JastAdd Forums Troubleshooting Question about broadcast attributes
Document Actions

Question about broadcast attributes

Up to Troubleshooting

Question about broadcast attributes

Posted by Bob Albright at March 24. 2008

Hi,


 


I just started using JastAdd so please excuse me if this is a silly question.  But I've run up against what should be a very simple problem and simply can't figure out the correct way to proceed.  If you have any advice I'd appreciate it.


All I want to do is associate all type literals in my grammar with the associated ClassDecl for that type.  Given that the class information is very close to the top of the AST structure I am essentially trying to find a hack such that I can get to the root, or near the root, of the AST.  I noticed that by adding an inherited broadcast attribute near the very top of the AST structure I might be able to do just this.  This works fine except that it gives me an error message that I do not understand.


 


  [jastadd] VarDecl->ClassType

  [jastadd] NameResolution.jrag:41 Missing inherited equation for attribute type

Lookup in class ClassType when being child of VarDecl


 


Can you explain what the `VarDecl->ClassType ` line means?  I don't understand how this does not start at the top of the AST and walk its way down to the ClassType.  And is there a better way with JastAdd to do what I want?  It shouldn't be terribly complicated but I think I designed my AST heirarchy in such a way that it makes it difficult.  Are there caveats in how the AST structure is declared that affect inherited attributes?


 


Thanks!


Bob Albright


rfa5@cornell.edu


 


 


Here's a snippet from my AST hierarchy:


Script ::= Dfile [Sfile];
Dfile  ::= ClassDecl*;
Decl ::= <Name:String>;
VarDecl: Decl ::= Type;
ClassDecl : Decl     ::= Fields;
Fields                ::= StateField* EffectField* UpdateField*;
StateField  : VarDecl;
EffectField : VarDecl ::= Combinator;


...


abstract Type;


NumberType : Type;


ClassType : Type ::= <Name:String>;


SetType : Type ::= Type;


...


Sfile ::= ClassType Block;


 


 


 


 


Re: Question about broadcast attributes

Posted by Torbjörn Ekman at March 25. 2008

Hi Bob,


It is often convenient to make sure that the AST hierarchy describes a tree, i.e., there is a path from each node to a common root node. From the grammar fragment above it seems like the Script node is a root node for most other nodes. However, looking at the grammar it seems like VarDecl can also be a root node. That node can in turn have a child of type ClassType. If we try to read the type() attribute in such a ClassType node we can thus not guarantee that there is a corresponding equation to the inherited attribute. The error message prints a path, from a root node to a node holding an inherited attribute, that does not contain an equation for the attribute. In this particular case this is a single VarDecl having a ClassType child.


For the grammar above I think the question is for which productions that VarDecl or even Decl can occur on the right hand side. Where do you plan to use VarDecl? Would it for instance make sense to turn Fields into a list of VarDecls and let the parser constrain the choices to State, Effect, and Update?  A hack to get you forward would be to add an optional child Decl to Script which forces the grammar to have the single root node.


The strategy to use broadcasting in this situation seems very appropriate. Does Script define equations for its children? Some more hints about NameResolution.jrag would help to further diagnose the problem.


Best regards


Torbjörn


 


Powered by Ploneboard