示例#1
0
 protected virtual void CheckForGlobalScopeTokenConflict(AttributeScope scope)
 {
     if (grammar.GetTokenType(scope.Name) != Label.INVALID)
     {
         ErrorManager.GrammarError(ErrorManager.MSG_SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE,
                                   grammar, null, scope.Name);
     }
 }
示例#2
0
        /** Return the scope containing name */
        public virtual AttributeScope GetAttributeScope(string name)
        {
            AttributeScope scope = GetLocalAttributeScope(name);

            if (scope != null)
            {
                return(scope);
            }
            if (RuleScope != null && RuleScope.GetAttribute(name) != null)
            {
                scope = RuleScope;
            }
            return(scope);
        }
示例#3
0
        /** If you label a rule reference, you can access that rule's
         *  return values as well as any predefined attributes.
         */
        public override Attribute GetAttribute(string name)
        {
            AttributeScope rulePropertiesScope =
                RuleLabelScope.grammarTypeToRulePropertiesScope[(int)Grammar.type];

            if (rulePropertiesScope.GetAttribute(name) != null)
            {
                return(rulePropertiesScope.GetAttribute(name));
            }

            if (referencedRule.ReturnScope != null)
            {
                return(referencedRule.ReturnScope.GetAttribute(name));
            }
            return(null);
        }
示例#4
0
        static RuleLabelScope()
        {
            predefinedRulePropertiesScope = new AttributeScope("RulePredefined", null);
            predefinedRulePropertiesScope.AddAttribute("text", null);
            predefinedRulePropertiesScope.AddAttribute("start", null);
            predefinedRulePropertiesScope.AddAttribute("stop", null);
            predefinedRulePropertiesScope.AddAttribute("tree", null);
            predefinedRulePropertiesScope.AddAttribute("st", null);
            predefinedRulePropertiesScope.IsPredefinedRuleScope = true;

            predefinedTreeRulePropertiesScope = new AttributeScope("RulePredefined", null);
            predefinedTreeRulePropertiesScope.AddAttribute("text", null);
            predefinedTreeRulePropertiesScope.AddAttribute("start", null);   // note: no stop; not meaningful
            predefinedTreeRulePropertiesScope.AddAttribute("tree", null);
            predefinedTreeRulePropertiesScope.AddAttribute("st", null);
            predefinedTreeRulePropertiesScope.IsPredefinedRuleScope = true;

            predefinedLexerRulePropertiesScope = new AttributeScope("LexerRulePredefined", null);
            predefinedLexerRulePropertiesScope.AddAttribute("text", null);
            predefinedLexerRulePropertiesScope.AddAttribute("type", null);
            predefinedLexerRulePropertiesScope.AddAttribute("line", null);
            predefinedLexerRulePropertiesScope.AddAttribute("index", null);
            predefinedLexerRulePropertiesScope.AddAttribute("pos", null);
            predefinedLexerRulePropertiesScope.AddAttribute("channel", null);
            predefinedLexerRulePropertiesScope.AddAttribute("start", null);
            predefinedLexerRulePropertiesScope.AddAttribute("stop", null);
            predefinedLexerRulePropertiesScope.AddAttribute("int", null);
            predefinedLexerRulePropertiesScope.IsPredefinedLexerRuleScope = true;

            grammarTypeToRulePropertiesScope =
                new AttributeScope[]
            {
                null,
                predefinedLexerRulePropertiesScope, // LEXER
                predefinedRulePropertiesScope,      // PARSER
                predefinedTreeRulePropertiesScope,  // TREE PARSER
                predefinedRulePropertiesScope       // COMBINED
            };
        }
示例#5
0
        /** Return the set of keys that collide from
         *  this and other.
         */
        public virtual HashSet <object> Intersection(AttributeScope other)
        {
            if (other == null || other.Count == 0 || Count == 0)
            {
                return(null);
            }
            HashSet <object> inter = new HashSet <object>();

            foreach (Attribute attr in attributes)
            {
                string key = attr.Name;
                if (other.GetAttribute(key) != null)
                {
                    inter.Add(key);
                }
            }
            if (inter.Count == 0)
            {
                return(null);
            }
            return(inter);
        }
示例#6
0
        static RuleLabelScope()
        {
            predefinedRulePropertiesScope = new AttributeScope( "RulePredefined", null );
            predefinedRulePropertiesScope.AddAttribute( "text", null );
            predefinedRulePropertiesScope.AddAttribute( "start", null );
            predefinedRulePropertiesScope.AddAttribute( "stop", null );
            predefinedRulePropertiesScope.AddAttribute( "tree", null );
            predefinedRulePropertiesScope.AddAttribute( "st", null );
            predefinedRulePropertiesScope.isPredefinedRuleScope = true;

            predefinedTreeRulePropertiesScope = new AttributeScope( "RulePredefined", null );
            predefinedTreeRulePropertiesScope.AddAttribute( "text", null );
            predefinedTreeRulePropertiesScope.AddAttribute( "start", null ); // note: no stop; not meaningful
            predefinedTreeRulePropertiesScope.AddAttribute( "tree", null );
            predefinedTreeRulePropertiesScope.AddAttribute( "st", null );
            predefinedTreeRulePropertiesScope.isPredefinedRuleScope = true;

            predefinedLexerRulePropertiesScope = new AttributeScope( "LexerRulePredefined", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "text", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "type", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "line", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "index", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "pos", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "channel", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "start", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "stop", null );
            predefinedLexerRulePropertiesScope.AddAttribute( "int", null );
            predefinedLexerRulePropertiesScope.isPredefinedLexerRuleScope = true;

            grammarTypeToRulePropertiesScope =
                new AttributeScope[]
                {
                    null,
                    predefinedLexerRulePropertiesScope, // LEXER
                    predefinedRulePropertiesScope, // PARSER
                    predefinedTreeRulePropertiesScope, // TREE PARSER
                    predefinedRulePropertiesScope // COMBINED
                };
        }
示例#7
0
        /** Get the arg, return value, or predefined property for this rule */
        public virtual AttributeScope GetLocalAttributeScope(string name)
        {
            AttributeScope scope = null;

            if (ReturnScope != null && ReturnScope.GetAttribute(name) != null)
            {
                scope = ReturnScope;
            }
            else if (ParameterScope != null && ParameterScope.GetAttribute(name) != null)
            {
                scope = ParameterScope;
            }
            else
            {
                AttributeScope rulePropertiesScope =
                    RuleLabelScope.grammarTypeToRulePropertiesScope[(int)Grammar.type];
                if (rulePropertiesScope.GetAttribute(name) != null)
                {
                    scope = rulePropertiesScope;
                }
            }
            return(scope);
        }
示例#8
0
 protected virtual void CheckForGlobalScopeTokenConflict( AttributeScope scope )
 {
     if ( grammar.GetTokenType( scope.Name ) != Label.INVALID )
     {
         ErrorManager.GrammarError( ErrorManager.MSG_SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE,
                                   grammar, null, scope.Name );
     }
 }
示例#9
0
 public virtual AttributeScope DefineGlobalScope( string name, IToken scopeAction )
 {
     AttributeScope scope = new AttributeScope( this, name, scopeAction );
     scopes[name] = scope;
     return scope;
 }
示例#10
0
 public virtual AttributeScope CreateRuleScope( string ruleName, IToken scopeAction )
 {
     AttributeScope scope = new AttributeScope( this, ruleName, scopeAction );
     scope.IsDynamicRuleScope = true;
     return scope;
 }
示例#11
0
 public virtual AttributeScope CreateReturnScope( string ruleName, IToken retAction )
 {
     AttributeScope scope = new AttributeScope( this, ruleName, retAction );
     scope.IsReturnScope = true;
     return scope;
 }
示例#12
0
 public virtual AttributeScope CreateParameterScope( string ruleName, IToken argAction )
 {
     AttributeScope scope = new AttributeScope( this, ruleName, argAction );
     scope.IsParameterScope = true;
     return scope;
 }
示例#13
0
 /** Return the set of keys that collide from
  *  this and other.
  */
 public virtual HashSet<object> Intersection( AttributeScope other )
 {
     if ( other == null || other.Count == 0 || Count == 0 )
     {
         return null;
     }
     HashSet<object> inter = new HashSet<object>();
     foreach ( Attribute attr in _attributes )
     {
         string key = attr.Name;
         if ( other.GetAttribute( key ) != null )
         {
             inter.Add( key );
         }
     }
     if ( inter.Count == 0 )
     {
         return null;
     }
     return inter;
 }