/// <summary> /// Builds the trees. /// </summary> /// <param name="chart">The current chart.</param> /// <param name="startCat">The start category.</param> /// <returns>A list of trees.</returns> public List<Tree> BuildTrees(Chart chart, ConcreteCategory startCat) { List<Tree> temp = new List<Tree>(); for (int catID = startCat.FirstFID; catID < startCat.LastFID + 1; catID++) { int? cat = chart.LookupPC(catID, 0, 0); // TODO what should last value be? // int? cat = chart.GetCategory(catID, 0, 0, chart.nextId); TODO length=nextId? nope if (cat.HasValue) { temp.AddRange(this.MkTreesForCat(cat.Value, chart)); } } return temp; }
public List<string> Predict2(Chart chart) { List<string> tokens = new List<string>(); foreach(ActiveItem ai in this.Value) { foreach(int arg in ai.Args) { // Get all the arguments foreach(Production p in chart.ExpandForest(arg)) { // TODO } } } return tokens; }
/// <summary> /// Used to predict the next correct tokens /// </summary> /// <returns>A list of predictions</returns> public List<string> Predict(Chart chart) { List<string> tokens = new List<string>(); foreach(ActiveItem ai in this.Value) { if (ai.Seq.Count > ai.Dot) { Symbol s = ai.Seq[ai.Dot]; if (s is SymbolKS) { SymbolKS sks = (SymbolKS)s; if (sks.Tokens.Length > 0) { tokens.Add(sks.Tokens[0]); } } else if (s is SymbolKP) { SymbolKP skp = (SymbolKP)s; if (skp.Tokens.Length > 0) { // TODO check if correct, before [0] foreach (Symbol newSymbol in skp.Tokens) { if (newSymbol is SymbolKS) { // TODO is this correct? tokens.AddRange(((SymbolKS)newSymbol).Tokens); } else if (newSymbol is SymbolBind) { tokens.Add("&+"); } else if (newSymbol is SymbolSoftBind) { } else if (newSymbol is SymbolSoftSpace) { } else if (newSymbol is SymbolCapit) { tokens.Add("&|"); } else if (newSymbol is SymbolAllCapit) { tokens.Add("&|"); } else { } } } } else if (s is SymbolLit) { SymbolLit slit = (SymbolLit)s; int arg = ai.Args[slit.Arg]; if (arg == -1) { // String tokens.Add("\"STRING\""); } else if (arg == -2) { // Int tokens.Add("123"); } else if (arg == -3) { // Float tokens.Add("3.14"); } else if (arg == -4) { // Var tokens.Add("\"VARIABLE\""); } } else if (s is SymbolCat) { SymbolCat scat = (SymbolCat)s; int fid = ai.Args[scat.Arg]; List<Production> prods = chart.ExpandForest(fid); foreach(Production p in prods) { if (p is ProductionApply) { var papp = (ProductionApply)p; } } } } } return tokens; }
/// <summary> /// Makes a tree with help of a production and a chart. /// </summary> /// <param name="p">An application production.</param> /// <param name="chart">The current chart.</param> /// <returns>A list of trees.</returns> public List<Tree> MkTreesForProduction(Production p, Chart chart) { List<Tree> temp = new List<Tree>(); if (p is ProductionApply) { var pa = (ProductionApply)p; if (pa.Domain().Length == 0) { temp.Add(new Application(pa.Function.Name, new List<Tree>())); return temp; } else { List<List<Tree>> lsmx = new List<List<Tree>>(); foreach (int pp in pa.Domain()) { if (pp != p.FId) { lsmx.Add(this.MkTreesForCat(pp, chart)); // TODO fix since it can create endless trees. } } foreach (List<Tree> tree in this.ListMixer(lsmx)) { temp.Add(new Application(pa.Function.Name, tree)); } } } else if (p is ProductionConst) { var pc = (ProductionConst)p; temp.Add(new Literal(pc.Tokens[0], pc.Type)); } return temp; }
/// <summary> /// Makes a list of trees for a certain category with help of the current chart. /// </summary> /// <param name="cat">The category.</param> /// <param name="chart">The current chart.</param> /// <returns>A list of trees.</returns> public List<Tree> MkTreesForCat(int cat, Chart chart) { List<Tree> temp = new List<Tree>(); foreach (Production p in chart.ExpandForest(cat)) { temp.AddRange(this.MkTreesForProduction(p, chart)); } return temp; }
/// <summary> /// Initializes a new instance of the ParseState class. /// </summary> /// <param name="concrete">The concrete used to parse.</param> public ParseState(Concrete concrete) { this.concrete = concrete; this.startCat = concrete.GetStartCat(); this.items = new Trie(); this.chart = new Chart(concrete); ConcreteCategory tempcat = concrete.GetStartCat(); for (int fid = tempcat.FirstFID; fid <= tempcat.LastFID; fid++) { var prods = this.chart.ExpandForest(fid); foreach (ProductionApply k in prods) { k.Function.FixSymbols(); int lbl = 0; foreach (Symbol[] sym in k.Function.Sequences) { var activeItem = new ActiveItem(0, 0, k.Function, sym.ToList<Symbol>(), k.Domain().ToList<int>(), fid, lbl); this.items.Value.Add(activeItem); lbl++; } } } this.items.InsertChain(new List<string>(), this.items); }