Example #1
0
        private void ConvertNFAtoDFA()
        {
            mDFATable = new FSATable();

            if (mNFATable.GetStates().Count == 0)
            {
                return;
            }

            State.mStateIDCounter = 0;

            HashSet <State> dfaStartStates;

            EpsilonClosure(out dfaStartStates, mNFATable.GetFirstState());

            State dfaStartState = new State(dfaStartStates);

            mDFATable.AppendState(dfaStartState);

            List <State> unmarkedDFAStates = new List <State>();

            unmarkedDFAStates.Add(dfaStartState);

            while (unmarkedDFAStates.Count != 0)
            {
                State processingDFAState = unmarkedDFAStates[unmarkedDFAStates.Count - 1];
                unmarkedDFAStates.RemoveAt(unmarkedDFAStates.Count - 1);

                foreach (char c in mInputSet)
                {
                    HashSet <State> moveResult, epsilonClosureResult;
                    Move(c, out moveResult, new HashSet <State>(processingDFAState.mNFAStates));
                    EpsilonClosure(out epsilonClosureResult, moveResult);

                    bool  found = false;
                    State s     = null;

                    for (int i = 0; i < mDFATable.GetStates().Count; ++i)
                    {
                        s = mDFATable.GetState(i);

                        if (s.mNFAStates.SetEquals(epsilonClosureResult))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found == false)
                    {
                        State u = new State(epsilonClosureResult);
                        unmarkedDFAStates.Add(u);
                        mDFATable.AppendState(u);

                        processingDFAState.AddTransition(c, u);
                    }
                    else
                    {
                        processingDFAState.AddTransition(c, s);
                    }
                }
            }
        }
Example #2
0
 private void CollapseChains()
 {
     CollapseChain(mDFATable.GetFirstState());
 }