private List <string> GetFirstPlus(string p, List <string> list) { if (list == null) { list = new List <string>(); } var grList = gramarList.FindAll(r => r.LeftToken == p); foreach (var gramarLine in grList) { string tempFirst = gramarLine.First(); if (list.Contains(tempFirst)) { continue; } list.Add(tempFirst); if (!GrammarLine.IsTerminal(tempFirst)) { GetFirstPlus(tempFirst, list); } } return(list); }
private bool GreaterLower() { for (int i = 1; i < outRelationshipsTable.Count; i++) { for (int j = 1; j < outRelationshipsTable[i].Count; j++) { if (outRelationshipsTable[i][j] == ".=") { if (!GrammarLine.IsTerminal(outRelationshipsTable[i][0]) || !GrammarLine.IsTerminal(outRelationshipsTable[0][j])) { List <string> lastPlus = new List <string>(GetLastPlus(outRelationshipsTable[i][0], null)); List <string> firstPlus = new List <string>(GetFirstPlus(outRelationshipsTable[0][j], null)); foreach (var a in lastPlus) { foreach (var f in firstPlus) { int k = outRelationshipsTable.FindIndex(r => r[0] == a); int kf = outRelationshipsTable.FindIndex(r => r[0] == f); if (outRelationshipsTable[k][kf] == "" || outRelationshipsTable[k][kf] == ".>") { outRelationshipsTable[k][kf] = ".>"; } } } } if (!GrammarLine.IsTerminal(outRelationshipsTable[i][0])) { List <string> lastPlus = new List <string>(GetLastPlus(outRelationshipsTable[i][0], null)); foreach (var a in lastPlus) { int k = outRelationshipsTable.FindIndex(r => r[0] == a); if (outRelationshipsTable[k][j] == "" || outRelationshipsTable[k][j] == ".>") { outRelationshipsTable[k][j] = ".>"; } else { outRelationshipsTable[k][j] += " Err " + ".>"; } } } if (!GrammarLine.IsTerminal(outRelationshipsTable[0][j])) { List <string> firstPlus = new List <string>(GetFirstPlus(outRelationshipsTable[0][j], null)); foreach (var a in firstPlus) { int k = outRelationshipsTable[0].FindIndex(r => r == a); if (outRelationshipsTable[i][k] == "" || outRelationshipsTable[i][k] == "<.") { outRelationshipsTable[i][k] = "<."; } else { outRelationshipsTable[i][k] += " Err " + "<."; } } } } } } return(true); }