internal void CloneItems(BuilderElements builders)
 {
     foreach (GrammarBuilderBase item in builders.Items)
     {
         _items.Add(item);
     }
 }
 private void RemoveDictionaryElements(SortedDictionary <int, Collection <BuilderElements> > dict)
 {
     foreach (GrammarBuilderBase item in Items)
     {
         BuilderElements builderElements = item as BuilderElements;
         if (builderElements != null)
         {
             builderElements.RemoveDictionaryElements(dict);
             dict[builderElements.Count].Remove(builderElements);
         }
     }
 }
        internal override int CalcCount(BuilderElements parent)
        {
            base.CalcCount(parent);
            int num = 1;

            foreach (GrammarBuilderBase item in Items)
            {
                num += item.CalcCount(this);
            }
            Count = num;
            return(num);
        }
        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;
                    }
                }
            }
        }
 private void GetDictionaryElements(SortedDictionary <int, Collection <BuilderElements> > dict)
 {
     foreach (GrammarBuilderBase item in Items)
     {
         BuilderElements builderElements = item as BuilderElements;
         if (builderElements != null)
         {
             if (!dict.ContainsKey(builderElements.Count))
             {
                 dict.Add(builderElements.Count, new Collection <BuilderElements>());
             }
             dict[builderElements.Count].Add(builderElements);
             builderElements.GetDictionaryElements(dict);
         }
     }
 }
        public override bool Equals(object obj)
        {
            BuilderElements builderElements = obj as BuilderElements;

            if (builderElements == null)
            {
                return(false);
            }
            if (builderElements.Count != Count || builderElements.Items.Count != Items.Count)
            {
                return(false);
            }
            for (int i = 0; i < Items.Count; i++)
            {
                if (!Items[i].Equals(builderElements.Items[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #7
0
 internal virtual int CalcCount(BuilderElements parent)
 {
     Marked = false;
     Parent = parent;
     return(Count);
 }
Пример #8
0
 internal override int CalcCount(BuilderElements parent)
 {
     _rule = null;
     return(base.CalcCount(parent));
 }