예제 #1
0
        static string ItemToString(ProductionItem item, bool doLA)
        {
            int lhsLength;
            var list    = new List <string>();
            var 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());
        }
예제 #2
0
파일: State.cs 프로젝트: traviolia/gppg
        private void AddKernel(Production production, int pos)
        {
            ProductionItem item = new ProductionItem(production, pos);

            kernelItems.Add(item);
            allItems.Add(item);
        }
예제 #3
0
		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;
		}
예제 #4
0
파일: State.cs 프로젝트: traviolia/gppg
        private void AddNonKernel(Production production)
        {
            ProductionItem item = new ProductionItem(production, 0);

            if (!allItems.Contains(item))
            {
                allItems.Add(item);
                AddClosure(item);
            }
        }
예제 #5
0
		private void AddNonKernel(Production production)
		{
			ProductionItem item = new ProductionItem(production, 0);

			if (!allItems.Contains(item))
			{
				allItems.Add(item);
				AddClosure(item);
			}
		}
예제 #6
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);
			}
		}
예제 #7
0
파일: State.cs 프로젝트: traviolia/gppg
 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 void AddKernel(Production production, int pos)
 {
     ProductionItem item = new ProductionItem(production, pos);
     kernelItems.Add(item);
     allItems.Add(item);
 }
 internal Reduce(ProductionItem item)
 {
     this.item = item;
 }
예제 #10
0
 internal Reduce(ProductionItem item)
 {
     this.item = item;
 }
예제 #11
0
        public override bool Equals(object obj)
        {
            ProductionItem item = (ProductionItem)obj;

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