public AutomatonMaker(bool nondeterministic) { createdAutomatonCore = new AutomatonCore(nondeterministic); InitializeComponent(); this.DoubleClick += delegate(object sender, EventArgs e) { MouseEventArgs me = e as MouseEventArgs; AutomatonNodeMaker b = new AutomatonNodeMaker(this, false); b.Location = new Point(me.Location.X - 25, me.Location.Y - 25); b.Size = new Size(50, 50); b.FlatStyle = FlatStyle.Popup; b.Parent = this; this.Controls.Add(b); createdAutomatonCore.nodes.Add(b.createdAutomatonNodeCore); }; System.Windows.Forms.Timer refreshTimer = new System.Windows.Forms.Timer(); refreshTimer.Interval = (int)Math.Round(1000.0f / 30.0f); refreshTimer.Tick += delegate { this.Refresh(); this.Invalidate(); }; refreshTimer.Start(); }
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; }
/** * Construct an NDFA using the Thompson construction method. */ private static AutomatonCore buildNDFA(OperationTree parsedRegex) { //The (NDFA) core to hang our creation on. AutomatonCore core = new AutomatonCore(true); //The following variable is initialised incomplete LinkedList <AutomatonNodeCore> NDFA = thompsonSubset(parsedRegex); //We need to note the entry state and final state NDFA.First.Value.isBeginNode = true; NDFA.Last.Value.isEndNode = true; //And names to the states int nameNumber = 1; foreach (AutomatonNodeCore n in NDFA) { int tmp = nameNumber; //Modifiable clone string name = string.Empty; while (--tmp >= 0) { name = (char)('A' + tmp % 26) + name; tmp /= 26; } n.stateName = name; nameNumber++;//next name } //Add to core foreach (AutomatonNodeCore n in NDFA) { core.nodes.Add(n); } return(core); }
public static bool isDFA(AutomatonCore automatonCore) { if (!automatonCore.nondeterministic) { return(true); } List <char> symbols = new List <char>(); List <char> foundSymbols = new List <char>(); bool isFirst = true; foreach (AutomatonNodeCore node in automatonCore.nodes) { if (isFirst) { isFirst = false; foreach (AutomatonTransition automationTransition in node.children)//Fill symbol list { symbols.AddRange(automationTransition.acceptedSymbols); } if (containsDuplicate(symbols)) //Look for duplicates { return(false); } } else { foreach (AutomatonTransition automationTransition in node.children)//Fill foundsymbols, check for new ones { foreach (char c in automationTransition.acceptedSymbols) { if (symbols.Contains(c)) { foundSymbols.Add(c); } else { return(false); } } } if (containsDuplicate(foundSymbols)) //Check for duplicates { return(false); } if (foundSymbols.Count != symbols.Count) //Check whether they are all used { return(false); } foundSymbols = new List <char>(); } } return(true); }
public static AutomatonCore negateDFA(AutomatonCore automatonCore) { foreach (AutomatonNodeCore node in automatonCore.nodes) { node.isEndNode = !node.isEndNode; } return(automatonCore); }
public static AutomatonCore reverseDFA(AutomatonCore automatonCore) { AutomatonCore reverse = new AutomatonCore(true); //Fill in the nodes and BeginStates become Endstates and Endstates become Beginstates foreach (AutomatonNodeCore node in automatonCore.nodes) { AutomatonNodeCore newNode = new AutomatonNodeCore(); newNode.stateName = node.stateName; if (node.isBeginNode) { newNode.isEndNode = true; newNode.isBeginNode = false; } if (node.isEndNode) { newNode.isEndNode = false; newNode.isBeginNode = true; } reverse.nodes.Add(newNode); } foreach (AutomatonNodeCore node in automatonCore.nodes) { foreach (AutomatonTransition trans in node.children) { foreach (AutomatonNodeCore node1 in reverse.nodes) { if (node.stateName != node1.stateName)//Matches OG parent { continue; } foreach (AutomatonNodeCore node2 in reverse.nodes) { if (node2.stateName != trans.automatonNode.stateName)//Matches OG child { continue; } AutomatonTransition trans1 = new AutomatonTransition(node1); trans1.acceptedSymbols = trans.acceptedSymbols; node2.children.Add(trans1); AutomatonTransition trans2 = new AutomatonTransition(node2); trans2.acceptedSymbols = trans.acceptedSymbols; node1.parents.Add(trans2); break; } break; } } } return(reverse); }
public RegularGrammar(AutomatonCore automaton) { filling = true; symbols = new List <string>(); startSymbols = new List <string>(); alphabet = new List <string>(); endSymbols = new List <string>(); productionLines = new List <ProductLine>(); processAutomaton(automaton); }
public static void convertNames(AutomatonCore automatonCore) { for (int i = 0; i < automatonCore.nodes.Count; ++i) { if (i > 25) { automatonCore.nodes[i].stateName = "A" + (Convert.ToChar(65 + i)).ToString(); } else { automatonCore.nodes[i].stateName = (Convert.ToChar(65 + i)).ToString(); } } }
public static AutomatonCore toDFA(AutomatonCore automatonCore) { convertNames(automatonCore); //Stop if it's already deterministic if (!automatonCore.nondeterministic) { return(automatonCore); } //Once again, stop if it's already deterministic if (isDFA(automatonCore)) { automatonCore.nondeterministic = false; return(automatonCore); } //Add all beginNodes this this list List <AutomatonNodeCore> beginNodes = new List <AutomatonNodeCore>(); foreach (AutomatonNodeCore node in automatonCore.nodes) { if (node.isBeginNode) { beginNodes.Add(node); } } //Magic TODO: Add comments // statename alphabet destination-states Dictionary <string, Dictionary <char, HashSet <string> > > states = new Dictionary <string, Dictionary <char, HashSet <string> > >(); List <AutomatonNodeCore> iterationNodes = new List <AutomatonNodeCore>(); iterationNodes.AddRange(beginNodes); addChildrenOfBeginNodes(iterationNodes, states); makeNewStatesAfterBeginNodes(iterationNodes, states); int amountOfStateNames = 0; while (amountOfStateNames != iterationNodes.Count) { amountOfStateNames = iterationNodes.Count; addChildrenofNonBeginNodes(automatonCore.nodes, states); makeNewStatesAfterBeginNodes(iterationNodes, states);//TODO: Change name } return(statesToAutomatonCore(automatonCore.nodes, states)); }
public static AutomatonCore OrDFA(AutomatonCore core1, AutomatonCore core2) { AutomatonCore returnCore = prepareForOperator(core1, core2); foreach (AutomatonNodeCore nodeCore1 in returnCore.nodes) { string[] origins = nodeCore1.stateName.Split(','); foreach (AutomatonNodeCore nodeCore2 in core1.nodes) { if (nodeCore2.stateName == origins[0]) { foreach (AutomatonNodeCore nodeCore3 in core2.nodes) { if (nodeCore3.stateName == origins[1]) { if (nodeCore2.isBeginNode || nodeCore3.isBeginNode) { nodeCore1.isBeginNode = true; } else { nodeCore1.isBeginNode = false; } if (nodeCore2.isEndNode || nodeCore3.isEndNode) { nodeCore1.isEndNode = true; } else { nodeCore1.isEndNode = false; } break; } } break; } } } return(returnCore); }
}; //And normal letters/numerals for language public static AutomatonCore ParseRegex(string exp) { OperationTree ops; mutateExp(exp, out exp); //Remove whitespaces & add dots if (!validifyExp(exp)) //Check for bracet consistency and invalid characters { Console.INSTANCE.WriteLine("ERR: Invalid expression."); return(null); } ops = buildOperatorTree(exp); if (ops == null) { Console.INSTANCE.WriteLine("ERR: Operator Tree could not be constructed."); } Console.INSTANCE.WriteLine(ops.ToString()); //Dump AutomatonCore ndfa = buildNDFA(ops); if (ndfa == null) { Console.INSTANCE.WriteLine("Constructing NDFA failed"); } return(ndfa); }
private static AutomatonCore prepareForOperator(AutomatonCore core1, AutomatonCore core2)//Accounts for same alphabet { convertNames(core1); convertNames(core2); AutomatonCore returnCore = new AutomatonCore(false); HashSet <char> alphabet = new HashSet <char>(); foreach (AutomatonNodeCore nodeCore1 in core1.nodes) { foreach (AutomatonTransition trans1 in nodeCore1.children) { foreach (char alpha in trans1.acceptedSymbols) { alphabet.Add(alpha); } } } List <AutomatonNodeCore> newStatesAsNodes = new List <AutomatonNodeCore>(); foreach (AutomatonNodeCore nodeCore1 in core1.nodes) { foreach (AutomatonNodeCore nodeCore2 in core2.nodes) { AutomatonNodeCore nodeCore = new AutomatonNodeCore(); nodeCore.stateName = nodeCore1.stateName + "," + nodeCore2.stateName; newStatesAsNodes.Add(nodeCore); } } foreach (AutomatonNodeCore nodeCore1 in newStatesAsNodes) { string[] origins = nodeCore1.stateName.Split(','); Dictionary <char, string> childs = new Dictionary <char, string>(); foreach (AutomatonNodeCore ogCore1 in core1.nodes) { if (ogCore1.stateName == origins[0]) { foreach (AutomatonTransition ogTrans1 in ogCore1.children) { foreach (char alpha in ogTrans1.acceptedSymbols) { childs[alpha] = ogTrans1.automatonNode.stateName; } } } } foreach (AutomatonNodeCore ogCore2 in core2.nodes) { if (ogCore2.stateName == origins[1]) { foreach (AutomatonTransition ogTrans2 in ogCore2.children) { foreach (char alpha in ogTrans2.acceptedSymbols) { childs[alpha] += "," + ogTrans2.automatonNode.stateName; } } } } foreach (KeyValuePair <char, string> child in childs) { foreach (AutomatonNodeCore nodeCore2 in newStatesAsNodes) { if (nodeCore2.stateName == child.Value) { AutomatonTransition trans3 = new AutomatonTransition(nodeCore2); trans3.acceptedSymbols.Add(child.Key); nodeCore1.children.Add(trans3); AutomatonTransition trans4 = new AutomatonTransition(nodeCore1); trans4.acceptedSymbols.Add(child.Key); nodeCore2.parents.Add(trans4); break; } } } } returnCore.nodes.AddRange(newStatesAsNodes); return(returnCore); }
public static AutomatonCore DFAMinimize(AutomatonCore automatonCore) { return(toDFA(reverseDFA(toDFA(reverseDFA(automatonCore))))); }
private static AutomatonCore statesToAutomatonCore(List <AutomatonNodeCore> originalAutomatonNodes, Dictionary <string, Dictionary <char, HashSet <string> > > states) { AutomatonCore automatonCore = new AutomatonCore(true); foreach (KeyValuePair <string, Dictionary <char, HashSet <string> > > state in states) { AutomatonNodeCore node = new AutomatonNodeCore(); string[] parts = state.Key.Trim().Split(','); foreach (AutomatonNodeCore ogNode in originalAutomatonNodes) { bool contains = false; foreach (string item in parts) { if (item == ogNode.stateName) { contains = true; break; } } if (!contains) { continue; } if (ogNode.isBeginNode) { node.isBeginNode = true; } if (ogNode.isEndNode) { node.isEndNode = true; } } node.stateName = state.Key; automatonCore.nodes.Add(node); } foreach (AutomatonNodeCore node in automatonCore.nodes) { Dictionary <char, HashSet <string> > state = states[node.stateName]; foreach (KeyValuePair <char, HashSet <string> > alphaStatePair in state) { string childStateName = ""; bool first = true; foreach (string childNamePart in alphaStatePair.Value) { if (!first) { childStateName += ","; } childStateName += childNamePart; first = false; } foreach (AutomatonNodeCore node2 in automatonCore.nodes) { if (node2.stateName != childStateName) { continue; } AutomatonTransition trans1 = new AutomatonTransition(node2); trans1.acceptedSymbols.Add(alphaStatePair.Key); node.children.Add(trans1); AutomatonTransition trans2 = new AutomatonTransition(node); trans2.acceptedSymbols.Add(alphaStatePair.Key); node2.parents.Add(trans2); break; } } } HashSet <char> alphabet = new HashSet <char>(); foreach (AutomatonNodeCore node in originalAutomatonNodes) { foreach (AutomatonTransition trans in node.children) { foreach (char alpha in trans.acceptedSymbols) { alphabet.Add(alpha); } } } bool errorStateMade = false; AutomatonNodeCore errorState = null; foreach (AutomatonNodeCore node1 in automatonCore.nodes) { HashSet <char> containingAlphabet = new HashSet <char>(); foreach (AutomatonTransition trans5 in node1.children) { foreach (char alpha in trans5.acceptedSymbols) { containingAlphabet.Add(alpha); } } if (containingAlphabet.Count != alphabet.Count && !errorStateMade) { errorState = new AutomatonNodeCore(); errorState.stateName = "ø"; AutomatonTransition trans1 = new AutomatonTransition(errorState); foreach (char alpha in alphabet) { trans1.acceptedSymbols.Add(alpha); } errorState.children.Add(trans1); errorStateMade = true; } if (containingAlphabet.Count != alphabet.Count) { foreach (char alpha in alphabet) { bool found = false; foreach (AutomatonTransition trans6 in node1.children) { foreach (char alpha2 in trans6.acceptedSymbols) { if (alpha2 == alpha) { found = true; break; } } if (found) { break; } } if (!found) { AutomatonTransition trans1 = new AutomatonTransition(node1); trans1.acceptedSymbols.Add(alpha); errorState.parents.Add(trans1); AutomatonTransition trans2 = new AutomatonTransition(errorState); trans2.acceptedSymbols.Add(alpha); node1.children.Add(trans2); } } } } if (errorStateMade) { automatonCore.nodes.Add(errorState); } automatonCore.nondeterministic = false; return(automatonCore); }
public AutomatonCore changeToNDFA() { AutomatonCore automatonCore = new AutomatonCore(true); foreach (string symbol in symbols) { AutomatonNodeCore ac = new AutomatonNodeCore(); ac.stateName = symbol; if (startSymbols.Contains(symbol)) { ac.isBeginNode = true; ac.isEndNode = false; } else if (endSymbols.Contains(symbol)) { ac.isBeginNode = false; ac.isEndNode = true; } else { ac.isBeginNode = false; ac.isEndNode = false; } automatonCore.nodes.Add(ac); } foreach (ProductLine pl in productionLines) { foreach (AutomatonNodeCore node in automatonCore.nodes) { if (pl.fromSymbol == node.stateName) { //add to children bool newTrans = true; //Check if there already is a transition with the samen nodecores //If there is, add the extra state letter foreach (AutomatonTransition tr in node.children) { if (tr.automatonNode.stateName == pl.toSymbol) { tr.acceptedSymbols.Add(pl.letter[0]); newTrans = false; } } if (newTrans) { AutomatonTransition trans = null; foreach (AutomatonNodeCore endNode in automatonCore.nodes) { if (endNode.stateName == pl.toSymbol) { trans = new AutomatonTransition(endNode); } } trans.acceptedSymbols.Add(pl.letter[0]); node.children.Add(trans); } } else if (pl.toSymbol == node.stateName) { //add to parent bool newTrans = true; //Check if there already is a transition with the samen nodecores //If there is, add the extra state letter foreach (AutomatonTransition tr in node.parents) { if (tr.automatonNode.stateName == pl.toSymbol) { tr.acceptedSymbols.Add(pl.letter[0]); newTrans = false; } } if (newTrans) { AutomatonTransition trans = null; foreach (AutomatonNodeCore firstNode in automatonCore.nodes) { if (firstNode.stateName == pl.fromSymbol) { trans = new AutomatonTransition(firstNode); } } trans.acceptedSymbols.Add(pl.letter[0]); node.parents.Add(trans); } } } } return(automatonCore); }
//int totalColumns = 2; //int totalRows = 0; //List<string> columnAlphabet; public AutomatonTable(AutomatonCore automaton) { InitializeComponent(); dataTable.AutoGenerateColumns = false; HashSet <char> alphabet = new HashSet <char>(); foreach (AutomatonNodeCore node in automaton.nodes) { foreach (AutomatonTransition transition in node.children) { foreach (char alpha in transition.acceptedSymbols) { alphabet.Add(alpha); } } } List <char> alphabetList = alphabet.OrderBy(alpha => alpha).ToList <char>(); for (int i = 1; i <= alphabet.Count; i++) { dataTable.Columns.Add(alphabetList[i - 1].ToString(), alphabetList[i - 1].ToString()); } if (automaton.nondeterministic) { dataTable.Columns.Add("epsilon", "ε"); } for (int j = 0; j < automaton.nodes.Count; j++) { dataTable.Rows.Add(); Dictionary <char, string> cellValueByAlphabet = new Dictionary <char, string>(); foreach (AutomatonTransition trans in automaton.nodes[j].children) { if (trans.acceptedSymbols.Count != 0) { foreach (char alpha in trans.acceptedSymbols) { for (int i = 0; i < alphabetList.Count; i++) { if (alphabetList[i] == alpha) { if (cellValueByAlphabet.ContainsKey(alpha)) { cellValueByAlphabet[alpha] += ", "; } else { cellValueByAlphabet[alpha] = ""; } cellValueByAlphabet[alpha] += trans.automatonNode.stateName; } } } } else if (automaton.nondeterministic) { if (cellValueByAlphabet.ContainsKey('ε')) { cellValueByAlphabet['ε'] += ", "; } else { cellValueByAlphabet['ε'] = ""; } cellValueByAlphabet['ε'] += trans.automatonNode.stateName; } } foreach (KeyValuePair <char, string> item in cellValueByAlphabet) { for (int i = 0; i <= alphabet.Count - (automaton.nondeterministic ? 0 : 1); i++) { if (dataTable.Columns[i].HeaderText == item.Key.ToString()) { dataTable.Rows[j].Cells[i].Value = item.Value; } } } dataTable.Rows[j].HeaderCell.Value = (automaton.nodes[j].isBeginNode ? "->" : "") + (automaton.nodes[j].isEndNode ? "*" : "") + automaton.nodes[j].stateName; } }
public static void Create() { #region Add command CommandsList.Add(new Command("DFA", "Play with (N)DFAs.\n" + "Controls:\n" + "Leftern Double Click - New Node\n" + "Rightern Double Click - Remove Node\n" + "Drag - Move Node\n" + "Click - Select / Deselect Node\n" + "Enter when selecting - Make Start Node / Undo Making Start Node\n" + "Tab Then Selecting - Transition Maker Enabled / Transition Maker Disabled\n" + "Click When Transition Making - New Transition / Remove Transition\n" + "Keyup - Assign State Name", delegate(string paramaters) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.CreateNew(false); })); CommandsList.Add(new Command("NDFA", "Play with (N)DFAs.\n" + "Controls:\n" + "Leftern Double Click - New Node\n" + "Rightern Double Click - Remove Node\n" + "Drag - Move Node\n" + "Click - Select / Deselect Node\n" + "Enter when selecting - Make Start Node / Undo Making Start Node\n" + "Tab Then Selecting - Transition Maker Enabled / Transition Maker Disabled\n" + "Click When Transition Making - New Transition / Remove Transition\n" + "Keyup - Assign State Name", delegate(string paramaters) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.CreateNew(true); })); CommandsList.Add(new Command("DFAAnd", "Uses the AND operator on save slot (0-9, 0-9) and places the new DFA in the current save slot", delegate(string paramaters) { string[] parts = paramaters.Split(' '); int a; int b; if (parts.Length == 2) { if (int.TryParse(parts[0], out a) && int.TryParse(parts[1], out b)) { if (Console.INSTANCE.processedResults[a] is AutomatonCore && Console.INSTANCE.processedResults[b] is AutomatonCore) { if (!(Console.INSTANCE.processedResults[a] as AutomatonCore).nondeterministic && !(Console.INSTANCE.processedResults[b] as AutomatonCore).nondeterministic) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.AndDFA(Console.INSTANCE.processedResults[a] as AutomatonCore, Console.INSTANCE.processedResults[b] as AutomatonCore); } } } } })); CommandsList.Add(new Command("DFAOr", "Uses the OR operator on save slot (0-9, 0-9) and places the new DFA in the current save slot", delegate(string paramaters) { string[] parts = paramaters.Split(' '); int a; int b; if (parts.Length == 2) { if (int.TryParse(parts[0], out a) && int.TryParse(parts[1], out b)) { if (Console.INSTANCE.processedResults[a] is AutomatonCore && Console.INSTANCE.processedResults[b] is AutomatonCore) { if (!(Console.INSTANCE.processedResults[a] as AutomatonCore).nondeterministic && !(Console.INSTANCE.processedResults[b] as AutomatonCore).nondeterministic) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.OrDFA(Console.INSTANCE.processedResults[a] as AutomatonCore, Console.INSTANCE.processedResults[b] as AutomatonCore); } } } } })); CommandsList.Add(new Command("ChangeSaveSlot", "Changes the current save slot (0-9)", delegate(string paramaters) { int i = 0; if (int.TryParse(paramaters, out i)) { if (i < amountOfSaveSlots) { Console.INSTANCE.currentSaveSlot = i; Console.INSTANCE.WriteLine("Current Save Slot is now: " + i); } } })); CommandsList.Add(new Command("isPreviousItemDFA", "Check whether the last made object is a DFA", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore) { Console.INSTANCE.WriteLine("Was the previous automaton deterministic?: " + (AutomatonMaker.isDFA(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore) ? "true" : "false")); } else { Console.INSTANCE.WriteLine("The previous result was not an automaton."); //TODO: Check for other needs } })); CommandsList.Add(new Command("convertPreviousNDFAToDFA", "ConvertNDFAToDFA", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.toDFA(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore); } else { Console.INSTANCE.WriteLine("The previous result was not an automaton."); //TODO: Check for other needs } })); CommandsList.Add(new Command("ItemIs", "Prints what the saved item is", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore) { Console.INSTANCE.WriteLine("Result is " + ((Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore).nondeterministic ? "NDFA" : "DFA")); } else if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is RegularGrammar) { Console.INSTANCE.WriteLine("Result is Grammar"); } else if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] == null) { Console.INSTANCE.WriteLine("Result is empty"); } })); CommandsList.Add(new Command("Grammar", "Play with formal grammar.", delegate(string paramaters) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = new RegularGrammar(); Console.INSTANCE.WriteLine("Type the symbols."); Console.INSTANCE.WriteLine("Example: A, B"); })); /* CommandsList.Add(new Command("Regex", * "Play with regular expressions.", * delegate(string paramaters) * { * Window.INSTANCE.WriteLine("Params: " + paramaters); * //Regex.ParseRegex(paramaters); * }));*/ CommandsList.Add(new Command("Exit", "Quit the program.", delegate(string paramaters) { Program.Terminate(); })); CommandsList.Add(new Command("GrammarString", "Do grammar string thing.", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is RegularGrammar) { Console.INSTANCE.WriteLine((Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as RegularGrammar).toString()); } })); CommandsList.Add(new Command("GrammarToNDFA", "Convert Grammar to NDFA", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is RegularGrammar) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as RegularGrammar).changeToNDFA(); Console.INSTANCE.WriteLine("The NDFA has made from the grammar"); } })); CommandsList.Add(new Command("ShowAutomaton", "Shows the automaton in a table", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore) { //Window.INSTANCE.processedResults[Window.INSTANCE.currentSaveSlot]; AutomatonTable table = new AutomatonTable(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore); table.ShowDialog(); } })); CommandsList.Add(new Command("DFAReverse", "Reverse the DFA/NDFA, new Automaton will be NDFA", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore && !(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore).nondeterministic) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.reverseDFA(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore); } })); CommandsList.Add(new Command("DFANegate", "Negate the DFA/NDFA", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.negateDFA(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore); } })); CommandsList.Add(new Command("DFAMinimize", "Minimize the DFA", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore && !(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore).nondeterministic) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = AutomatonMaker.DFAMinimize(Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore); } })); CommandsList.Add(new Command("AutomatonToGrammar", "Convert Automaton to Grammar", delegate(string paramaters) { if (Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] is AutomatonCore) { Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = new RegularGrammar((Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] as AutomatonCore)); Console.INSTANCE.WriteLine("Automaton converted to Grammar"); } })); CommandsList.Add(new Command("Regex", "Fill in regex to perform operations on.\nShows the NDFA of the expression in a table", delegate(string parameters) { AutomatonCore regexNDFA = MyRegex.ParseRegex(parameters); if (regexNDFA != null) { AutomatonTable table = new AutomatonTable(regexNDFA); table.ShowDialog(); Console.INSTANCE.processedResults[Console.INSTANCE.currentSaveSlot] = regexNDFA; //Save our NDFA } } )); CommandsList.Add(new Command("Help", "This help command.", delegate(string parameters) { foreach (Command c in CommandsList) { Console.INSTANCE.WriteLine(c.ToString()); Console.INSTANCE.WriteLine(""); } })); CommandsList.Add(new Command("About", "About info", delegate(string parameters) { Console.INSTANCE.WriteLine("This application was made by:"); Console.INSTANCE.WriteLine("Patrick Bakx, "); Console.INSTANCE.WriteLine("Thom Trignol, &"); Console.INSTANCE.WriteLine("Julian West"); Console.INSTANCE.WriteLine("According to the criteria for the school subject"); Console.INSTANCE.WriteLine("Formal Language Theory"); })); #endregion }