예제 #1
0
        internal override GrammarBuilderBase Clone()
        {
            RuleElement ruleElement = new RuleElement(_name);

            ruleElement.CloneItems(this);
            return(ruleElement);
        }
예제 #2
0
        internal SemanticKeyElement(string semanticKey)
        {
            _semanticKey = semanticKey;
            RuleElement ruleElement = new RuleElement(semanticKey);

            _ruleRef = new RuleRefElement(ruleElement, _semanticKey);
            base.Items.Add(ruleElement);
            base.Items.Add(_ruleRef);
        }
        protected void Optimize(Collection <RuleElement> newRules)
        {
            SortedDictionary <int, Collection <BuilderElements> > sortedDictionary = new SortedDictionary <int, Collection <BuilderElements> >();

            GetDictionaryElements(sortedDictionary);
            int[] array = new int[sortedDictionary.Keys.Count];
            int   num   = array.Length - 1;

            foreach (int key in sortedDictionary.Keys)
            {
                array[num--] = key;
            }
            for (int i = 0; i < array.Length && array[i] >= 3; i++)
            {
                Collection <BuilderElements> collection = sortedDictionary[array[i]];
                for (int j = 0; j < collection.Count; j++)
                {
                    RuleElement    ruleElement    = null;
                    RuleRefElement ruleRefElement = null;
                    for (int k = j + 1; k < collection.Count; k++)
                    {
                        if (collection[j] == null || !collection[j].Equals(collection[k]))
                        {
                            continue;
                        }
                        BuilderElements builderElements = collection[k];
                        BuilderElements parent          = builderElements.Parent;
                        if (builderElements is SemanticKeyElement)
                        {
                            parent.Items[parent.Items.IndexOf(builderElements)] = collection[j];
                        }
                        else
                        {
                            if (ruleElement == null)
                            {
                                ruleElement = new RuleElement(builderElements, "_");
                                newRules.Add(ruleElement);
                            }
                            if (ruleRefElement == null)
                            {
                                ruleRefElement = new RuleRefElement(ruleElement);
                                collection[j].Parent.Items[collection[j].Parent.Items.IndexOf(collection[j])] = ruleRefElement;
                            }
                            parent.Items[builderElements.Parent.Items.IndexOf(builderElements)] = ruleRefElement;
                        }
                        builderElements.RemoveDictionaryElements(sortedDictionary);
                        collection[k] = null;
                    }
                }
            }
        }
예제 #4
0
        public override bool Equals(object obj)
        {
            RuleElement ruleElement = obj as RuleElement;

            if (ruleElement == null)
            {
                return(false);
            }
            if (!base.Equals(obj))
            {
                return(false);
            }
            return(_name == ruleElement._name);
        }
예제 #5
0
 internal RuleRefElement(RuleElement rule, string semanticKey)
 {
     _rule        = rule;
     _semanticKey = semanticKey;
 }
예제 #6
0
 internal RuleRefElement(RuleElement rule)
 {
     _rule = rule;
 }