Beispiel #1
0
        private void AddKernel(Production production, int pos)
        {
            ProductionItem item = new ProductionItem(production, pos);

            kernelItems.Add(item);
            allItems.Add(item);
        }
        static string ItemToString(ProductionItem item, bool doLA)
        {
            int           lhsLength;
            List <string> list = new List <string>();

            System.Text.StringBuilder builder = new System.Text.StringBuilder();

            builder.AppendFormat("{0} {1}: ", item.production.num, item.production.lhs);
            lhsLength = builder.Length;

            for (int i = 0; i < item.production.rhs.Count; i++)
            {
                if (i == item.pos)
                {
                    list.Add(".");
                }
                list.Add(item.production.rhs[i].ToString());
            }

            if (item.pos == item.production.rhs.Count)
            {
                list.Add(".");
            }

            builder.Append(ListUtilities.GetStringFromList(list, " ", lhsLength + 6));

            if (item.LA != null && doLA)
            {
                builder.AppendLine();
                builder.AppendFormat("\t-lookahead: {{ {0} }}", ListUtilities.GetStringFromList(item.LA, ", ", 16));
            }

            return(builder.ToString());
        }
Beispiel #3
0
        private void AddNonKernel(Production production)
        {
            ProductionItem item = new ProductionItem(production, 0);

            if (!allItems.Contains(item))
            {
                allItems.Add(item);
                AddClosure(item);
            }
        }
Beispiel #4
0
 private void AddClosure(ProductionItem item)
 {
     if (item.pos < item.production.rhs.Count)
     {
         NonTerminal nonTerm = null;
         Symbol      rhs     = item.production.rhs[item.pos];
         if ((nonTerm = rhs as NonTerminal) != null)
         {
             foreach (Production p in nonTerm.productions)
             {
                 AddNonKernel(p);
             }
         }
     }
 }
        private AutomatonState FindExistingState(Symbol sym, List <ProductionItem> itemSet)
        {
            if (accessedBy.ContainsKey(sym))
            {
                foreach (AutomatonState state in accessedBy[sym])
                {
                    if (ProductionItem.SameProductions(state.kernelItems, itemSet))
                    {
                        return(state);
                    }
                }
            }

            return(null);
        }
        public override bool Equals(object obj)
        {
            ProductionItem item = (ProductionItem)obj;

            return(item.pos == pos && item.production == production);
        }