private void btn_next_Click(object sender, EventArgs e) { if (tabControl1.SelectedIndex < tabControl1.TabCount) tabControl1.SelectedIndex += 1; if (btn_next.Text == Resources.DoneWord) { try { if (MachineType == machineType.Dfa) Machine = new DFA(States, Seqma, InitialState, FinalStates, Transitions); else Machine = new NFA(States, Seqma, InitialState, FinalStates, Transitions); Close(); } catch (Exception exception) { MessageBox.Show(exception.Message, Resources.ErrorWord, MessageBoxButtons.OK, MessageBoxIcon.Error); Console.WriteLine(exception); } } }
private void FillMachineComponent(DFA dfa) { try { label6.Text = Resources.MachineTypeWord + machineType.Dfa; button3.Visible = false; listBox1.Items.Clear(); listBox2.Items.Clear(); listBox3.Items.Clear(); listBox4.Items.Clear(); listBox5.Items.Clear(); foreach (var symbol in dfa.Symbols) { listBox1.Items.Add(symbol); } foreach (var state in dfa.States) { listBox2.Items.Add(state); } listBox3.Items.Add(InitialState); foreach (var finalState in dfa.FinalStates) { listBox4.Items.Add(finalState); } foreach (var transitionFunction in dfa.TransitionFunctions) { listBox5.Items.Add(transitionFunction); } } catch (Exception exception) { Console.WriteLine(exception); } }
private static void IsDFA(DFA DFA1) { ArrayList ar = new ArrayList(); //to be used for earasing duplicated entries //check for valid symbols var dupliChar = new List<char>(); foreach (object o in DFA1.m_symbols) { if (!(o is char)) throw new Exception ("one of your input symbols is not in the correct format"); char ch = (char) o; if (!dupliChar.Contains(ch)) dupliChar.Add(ch); } DFA1.m_symbols = dupliChar; //check for valid states ar.Clear(); foreach (object o in DFA1.m_states) { if (!(o is State)) throw new Exception ("one of your states is not in the correct format"); State st = o as State; if (!ar.Contains(st)) ar.Add(st); } DFA1.m_states = (IList) ar.Clone(); //check for valid final states foreach (object o in DFA1.m_final_states) if (!DFA1.m_states.Contains(o)) throw new Exception ("one of your final states doesn't exist in your states"); //check transition functions for duplicated ar.Clear(); var listdupli= new List<TransitionFunction>(); foreach (object o in DFA1.m_transition_functions) { if (!(o is ITransitionFunction)) { throw new Exception ("one of your functions is not in the correct format"); } TransitionFunction tf = o as TransitionFunction; //for repeated entries if (!listdupli.Contains(tf)) listdupli.Add(tf); } DFA1.m_transition_functions = listdupli; //check for valid functions according to input states foreach (ITransitionFunction Itf in DFA1.m_transition_functions) { if (!DFA1.m_states.Contains(Itf.InputState)) throw new Exception(String.Format("the state with name {0} doesn't exist in states", Itf.InputState.Name)); if (!DFA1.m_states.Contains(Itf.OutputState)) throw new Exception(String.Format("the state with name {0} doesn't exist in states", Itf.OutputState.Name)); if (!DFA1.m_symbols.Contains(Itf.InputSymbol)) throw new Exception(String.Format("the symbol with name {0} doesn't exist in symbols", Itf.InputSymbol.ToString())); } //check whether it is a deterministic DFA or it is a NFA >>case duplicated seqma foreach (ITransitionFunction Itf1 in DFA1.m_transition_functions) foreach (ITransitionFunction Itf2 in DFA1.m_transition_functions) if (Itf2.InputState == Itf1.InputState && Itf2.InputSymbol == Itf1.InputSymbol && Itf1.OutputState != Itf2.OutputState) throw new Exception("this is not a determenistic DFA"); foreach (IState state in DFA1.States) { List<TransitionFunction> StateTransition = DFA1.TransitionFunctions.FindAll(function => function.InputState.Name == state.Name); foreach (char symbol in DFA1.Symbols) { for (int i = 0; i < StateTransition.Count; i++) { var function = StateTransition[i]; if (function.InputSymbol == symbol) break; else { if (i== StateTransition.Count-1) throw new Exception("this is not a determenistic DFA"); else continue; } } } } }