Ejemplo n.º 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());
        }
Ejemplo n.º 2
0
        private void AddKernel(Production production, int pos)
        {
            ProductionItem item = new ProductionItem(production, pos);

            kernelItems.Add(item);
            allItems.Add(item);
        }
Ejemplo n.º 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;
		}
Ejemplo n.º 4
0
        private void AddNonKernel(Production production)
        {
            ProductionItem item = new ProductionItem(production, 0);

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

			if (!allItems.Contains(item))
			{
				allItems.Add(item);
				AddClosure(item);
			}
		}
Ejemplo n.º 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);
			}
		}
Ejemplo n.º 7
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 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;
 }
Ejemplo n.º 10
0
 internal Reduce(ProductionItem item)
 {
     this.item = item;
 }
Ejemplo n.º 11
0
        public override bool Equals(object obj)
        {
            ProductionItem item = (ProductionItem)obj;

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