示例#1
0
        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;
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        private void linkLabel7_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (listBox7.SelectedIndex >= 0 && listBox8.SelectedIndex >=0 && comboBox1.SelectedIndex>=0 )
                try
                {
                    var newTransFunc = new TransitionFunction(new State(listBox7.SelectedItem.ToString()), new State(listBox8.SelectedItem.ToString()), Convert.ToChar(comboBox1.SelectedItem.ToString()));

                    listBox9.Items.Add(newTransFunc);
                    Transitions.Add(newTransFunc);
                }
                catch (Exception exception)
                {
                    ConsoleWriter.Failure(exception.Message);
                }
           
        }