Beispiel #1
0
        static void GetAllStateAndInput(TransitionState stateStart, Hashset setAllState, Hashset setInputSymbols)
        {
            Hashset setUnprocessed = new Hashset();

            setUnprocessed.AddElement(stateStart);

            while (setUnprocessed.Count > 0)
            {
                TransitionState state = (TransitionState)setUnprocessed[0];

                setAllState.AddElement(state);
                setUnprocessed.RemoveElement(state);

                foreach (object objToken in state.GetAllKeys())
                {
                    string sSymbol = (string)objToken;
                    setInputSymbols.AddElement(sSymbol);

                    TransitionState[] arrTrans = state.GetTransitions(sSymbol);

                    if (arrTrans != null)
                    {
                        foreach (TransitionState stateEpsilon in arrTrans)
                        {
                            if (!setAllState.ElementExist(stateEpsilon))
                            {
                                setUnprocessed.AddElement(stateEpsilon);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private Hashset Eclosure(TransitionState stateStart)
        {
            Hashset setProcessed   = new Hashset();
            Hashset setUnprocessed = new Hashset();

            setUnprocessed.AddElement(stateStart);

            while (setUnprocessed.Count > 0)
            {
                TransitionState   state    = (TransitionState)setUnprocessed[0];
                TransitionState[] arrTrans = state.GetTransitions(MetaSymbol.EPSILON);
                setProcessed.AddElement(state);
                setUnprocessed.RemoveElement(state);

                if (arrTrans != null)
                {
                    foreach (TransitionState stateEpsilon in arrTrans)
                    {
                        if (!setProcessed.ElementExist(stateEpsilon))
                        {
                            setUnprocessed.AddElement(stateEpsilon);
                        }
                    }
                }
            }

            return(setProcessed);
        }
Beispiel #3
0
        private Hashset FindGroup(ArrayList arrGroup, TransitionState state)
        {
            foreach (object objSet in arrGroup)
            {
                Hashset set = objSet as Hashset;

                if (set.ElementExist(state) == true)
                {
                    return(set);
                }
            }

            return(null);
        }
Beispiel #4
0
        private TransitionState ReduceDfa(TransitionState stateStartDfa)
        {
            Hashset setInputSymbol = new Hashset();
            Hashset setAllDfaState = new Hashset();

            GetAllStateAndInput(stateStartDfa, setAllDfaState, setInputSymbol);

            TransitionState stateStartReducedDfa = null;
            ArrayList       arrGroup             = null;

            arrGroup = PartitionDfaGroups(setAllDfaState, setInputSymbol);

            foreach (object objGroup in arrGroup)
            {
                Hashset setGroup = (Hashset)objGroup;

                bool bAcceptingGroup = IsAcceptingGroup(setGroup);
                bool bStartingGroup  = setGroup.ElementExist(stateStartDfa);

                TransitionState stateRepresentative = (TransitionState)setGroup[0];

                if (bStartingGroup == true)
                {
                    stateStartReducedDfa = stateRepresentative;
                }

                if (bAcceptingGroup == true)
                {
                    stateRepresentative.AcceptingState = true;
                }

                if (setGroup.GetCardinality() == 1)
                {
                    continue;
                }

                setGroup.RemoveElement(stateRepresentative);

                TransitionState stateToBeReplaced = null;
                int             nReplecementCount = 0;
                foreach (object objStateToReplaced in setGroup)
                {
                    stateToBeReplaced = (TransitionState)objStateToReplaced;

                    setAllDfaState.RemoveElement(stateToBeReplaced);

                    foreach (object objState in setAllDfaState)
                    {
                        TransitionState state = (TransitionState)objState;
                        nReplecementCount += state.ReplaceTransitionState(stateToBeReplaced, stateRepresentative);
                    }
                }
            }

            int nIndex = 0;

            while (nIndex < setAllDfaState.Count)
            {
                TransitionState state = (TransitionState)setAllDfaState[nIndex];
                if (state.IsDeadState())
                {
                    setAllDfaState.RemoveAt(nIndex);
                    continue;
                }
                nIndex++;
            }

            return(stateStartReducedDfa);
        }