Ejemplo n.º 1
0
        private void ConvertNFAToDFA()
        {
            var nfaStates = m_nfa.States;

            //state 0 is an empty state. All invalid inputs go to state 0
            DFAState state0 = new DFAState();

            AddDFAState(state0);

            //state 1 is closure(nfaState[0])
            DFAState pre_state1    = new DFAState();
            int      nfaStartIndex = m_nfa.EntryEdge.TargetState.Index;

            Debug.Assert(nfaStartIndex >= 0);

            pre_state1.NFAStateSet.Add(nfaStartIndex);

            DFAState state1 = GetClosure(pre_state1);

            AddDFAState(state1);

            //begin algorithm
            int p = 1, j = 0;

            while (j <= p)
            {
                for (int symbol = CompactCharSetManager.MinClassIndex; symbol <= CompactCharSetManager.MaxClassIndex; symbol++)
                {
                    DFAState e = GetDFAState(m_dfaStates[j], symbol);

                    bool isSetExist = false;
                    for (int i = 0; i <= p; i++)
                    {
                        if (e.NFAStateSet.SetEquals(m_dfaStates[i].NFAStateSet))
                        {
                            //an existing dfa state

                            DFAEdge newEdge = new DFAEdge(symbol, m_dfaStates[i]);
                            m_dfaStates[j].AddEdge(newEdge);

                            isSetExist = true;
                        }
                    }

                    if (!isSetExist)
                    {
                        //a new set of nfa states (a new dfa state)
                        p += 1;
                        AddDFAState(e);

                        DFAEdge newEdge = new DFAEdge(symbol, e);
                        m_dfaStates[j].AddEdge(newEdge);
                    }
                }

                j += 1;
            }
        }
Ejemplo n.º 2
0
        private void ConvertNFAToDFA()
        {
            var nfaStates = m_nfa.States;

            //state 0 is an empty state. All invalid inputs go to state 0
            DFAState state0 = new DFAState();
            AddDFAState(state0);

            //state 1 is closure(nfaState[0])
            DFAState pre_state1 = new DFAState();
            int nfaStartIndex = m_nfa.EntryEdge.TargetState.Index;

            Debug.Assert(nfaStartIndex >= 0);

            pre_state1.NFAStateSet.Add(nfaStartIndex);

            DFAState state1 = GetClosure(pre_state1);
            AddDFAState(state1);

            //begin algorithm
            int p = 1, j = 0;
            while (j <= p)
            {
                for (int symbol = CompactCharSetManager.MinClassIndex; symbol <= CompactCharSetManager.MaxClassIndex; symbol++)
                {
                    DFAState e = GetDFAState(m_dfaStates[j], symbol);

                    bool isSetExist = false;
                    for (int i = 0; i <= p; i++)
                    {
                        if (e.NFAStateSet.SetEquals(m_dfaStates[i].NFAStateSet))
                        {
                            //an existing dfa state

                            DFAEdge newEdge = new DFAEdge(symbol, m_dfaStates[i]);
                            m_dfaStates[j].AddEdge(newEdge);

                            isSetExist = true;
                        }
                    }

                    if (!isSetExist)
                    {
                        //a new set of nfa states (a new dfa state)
                        p += 1;
                        AddDFAState(e);

                        DFAEdge newEdge = new DFAEdge(symbol, e);
                        m_dfaStates[j].AddEdge(newEdge);
                    }
                }

                j += 1;
            }
        }
Ejemplo n.º 3
0
        internal void AddEdge(DFAEdge edge)
        {
            CodeContract.RequiresArgumentNotNull(edge, "edge");

            m_outEdges.Add(edge);
        }
Ejemplo n.º 4
0
        internal void AddEdge(DFAEdge edge)
        {
            CodeContract.RequiresArgumentNotNull(edge, "edge");

            m_outEdges.Add(edge);
        }