private void processAutomaton(AutomatonCore automaton) { foreach (AutomatonNodeCore node in automaton.nodes) { symbols.Add(node.stateName); if (node.isBeginNode) { startSymbols.Add(node.stateName); } if (node.isEndNode) { endSymbols.Add(node.stateName); } foreach (AutomatonTransition trans in node.children) { foreach (char c in trans.acceptedSymbols) { ProductLine p = new ProductLine(node.stateName, c.ToString(), trans.automatonNode.stateName); productionLines.Add(p); if (!alphabet.Contains(c.ToString())) { alphabet.Add(c.ToString()); } } } } filling = false; }
public string processGrammar(string input) { string output = ""; switch (partToFill) { case "SYMBOLS": List <string> symbols = new List <string>(); string[] parts = input.Split(','); for (int i = 0; i < parts.Length; i++) { string symbol = parts[i]; string[] symbollist = symbol.Split(' '); if (symbollist.Length == 1) { symbol = symbollist[0]; } else if (symbollist.Length == 2) { symbol = symbollist[1]; } symbols.Add(symbol); } output = "Type the alphabet letters. \n"; output += "Example: a, b \n"; partToFill = "ALPHABET"; this.symbols = symbols; break; case "ALPHABET": List <string> letters = new List <string>(); parts = input.Split(','); for (int i = 0; i < parts.Length; i++) { string letter = parts[i]; string[] letterlist = letter.Split(' '); if (letterlist.Length == 1) { letter = letterlist[0]; } else if (letterlist.Length == 2) { letter = letterlist[1]; } letters.Add(letter); } output = "Type the ProductLines to add them in the list \n"; output += "Example: A, a, B \n"; output += "Type 'end' to end the list \n"; partToFill = "PRODUCTLINES"; this.alphabet = letters; break; case "PRODUCTLINES": parts = input.Split(','); if (parts[0].ToUpper() == "END") { output = "Type the StartSymbols \n"; output += "Example: A,C \n"; partToFill = "STARTSYMBOL"; } else { parts = input.Split(','); if (parts.Length == 3) { string startSymbol = ""; string transitionLetter = ""; string endSymbol = ""; for (int i = 0; i < parts.Length; i++) { string letter = parts[i]; string[] letterlist = letter.Split(' '); int index = 0; if (letterlist.Length == 1) { index = 0; } else if (letterlist.Length == 2) { index = 1; } switch (i) { case 0: startSymbol = letterlist[index]; break; case 1: transitionLetter = letterlist[index]; break; case 2: endSymbol = letterlist[index]; break; } } if (containsSymbol(startSymbol) && containsSymbol(endSymbol) && containsLetter(transitionLetter)) { ProductLine productLine = new ProductLine(startSymbol, transitionLetter, endSymbol); productionLines.Add(productLine); } else { output = "The given values are not available in the grammar \n"; } } } break; case "STARTSYMBOL": List <string> startsymbols = new List <string>(); parts = input.Split(','); for (int i = 0; i < parts.Length; i++) { if (containsSymbol(parts[i])) { string symbol = parts[i]; string[] symbollist = symbol.Split(' '); if (symbollist.Length == 1) { symbol = symbollist[0]; } else if (symbollist.Length == 2) { symbol = symbollist[1]; } startsymbols.Add(symbol); } } this.startSymbols = startsymbols; partToFill = "ENDSYMBOLS"; output = "Type the EndSymbols \n"; output += "Example: B,C \n"; break; case "ENDSYMBOLS": List <string> endsymbols = new List <string>(); parts = input.Split(','); for (int i = 0; i < parts.Length; i++) { if (containsSymbol(parts[i])) { string symbol = parts[i]; string[] symbollist = symbol.Split(' '); if (symbollist.Length == 1) { symbol = symbollist[0]; } else if (symbollist.Length == 2) { symbol = symbollist[1]; } endsymbols.Add(symbol); } } this.endSymbols = endsymbols; partToFill = ""; filling = false; output = "Grammar filled \n"; break; } return(output); }