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()); }
private void AddKernel(Production production, int pos) { ProductionItem item = new ProductionItem(production, pos); kernelItems.Add(item); allItems.Add(item); }
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; }
private void AddNonKernel(Production production) { ProductionItem item = new ProductionItem(production, 0); if (!allItems.Contains(item)) { allItems.Add(item); AddClosure(item); } }
private void AddNonKernel(Production production) { ProductionItem item = new ProductionItem(production, 0); if (!allItems.Contains(item)) { allItems.Add(item); AddClosure(item); } }
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 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; }
internal Reduce(ProductionItem item) { this.item = item; }
public override bool Equals(object obj) { ProductionItem item = (ProductionItem)obj; return(item.pos == pos && item.production == production); }