예제 #1
0
 /** From a chunk of text holding the definitions of the attributes,
  *  pull them apart and create an Attribute for each one.  Add to
  *  the list of attributes for this scope.  Pass in the character
  *  that terminates a definition such as ',' or ';'.  For example,
  *
  *  scope symbols {
  *  	int n;
  *  	List names;
  *  }
  *
  *  would pass in definitions equal to the text in between {...} and
  *  separator=';'.  It results in two Attribute objects.
  */
 public virtual void AddAttributes( string definitions, int separator )
 {
     IList<string> attrs = new List<string>();
     CodeGenerator.GetListOfArgumentsFromAction( definitions, 0, -1, separator, attrs );
     foreach ( string a in attrs )
     {
         Attribute attr = new Attribute( a );
         if ( !IsReturnScope && attr.InitValue != null )
         {
             ErrorManager.GrammarError( ErrorManager.MSG_ARG_INIT_VALUES_ILLEGAL,
                                       _grammar,
                                       _derivedFromToken,
                                       attr.Name );
             attr.InitValue = null; // wipe it out
         }
         for ( int i = 0; i <= _attributes.Count; i++ )
         {
             if ( i < _attributes.Count )
             {
                 if ( _attributes[i].Name == attr.Name )
                 {
                     _attributes[i] = attr;
                     break;
                 }
             }
             else
             {
                 _attributes.Add( attr );
                 // *must* break since the count changed
                 break;
                 //attributes.put( attr.Name, attr );
             }
         }
     }
 }
예제 #2
0
 /** Check for collision of a rule-scope dynamic attribute with:
  *  arg, return value, rule name itself.  Labels are checked elsewhere.
  */
 public virtual void CheckForRuleScopeAttributeConflict( Rule r, Attribute attribute )
 {
     int msgID = 0;
     object arg2 = null;
     string attrName = attribute.Name;
     if ( r.Name.Equals( attrName ) )
     {
         msgID = ErrorManager.MSG_ATTRIBUTE_CONFLICTS_WITH_RULE;
         arg2 = r.Name;
     }
     else if ( ( r.returnScope != null && r.returnScope.GetAttribute( attrName ) != null ) ||
               ( r.parameterScope != null && r.parameterScope.GetAttribute( attrName ) != null ) )
     {
         msgID = ErrorManager.MSG_ATTRIBUTE_CONFLICTS_WITH_RULE_ARG_RETVAL;
         arg2 = r.Name;
     }
     if ( msgID != 0 )
     {
         ErrorManager.GrammarError( msgID, grammar, r.tree.Token, attrName, arg2 );
     }
 }
예제 #3
0
 public virtual void AddAttribute( string name, string decl )
 {
     Attribute attr = new Attribute( name, decl );
     for ( int i = 0; i <= _attributes.Count; i++ )
     {
         if ( i < _attributes.Count )
         {
             if ( _attributes[i].Name == attr.Name )
             {
                 _attributes[i] = attr;
                 break;
             }
         }
         else
         {
             _attributes.Add( attr );
             // *must* break since the count changed
             break;
             //attributes.put( name, new Attribute( name, decl ) );
         }
     }
 }