Exemplo n.º 1
0
        static RegExpDfa HardOr(RegExpDfa one, RegExpDfa merged)
        {
            RegExpDfa dfa = new RegExpDfa(one);
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in merged.GetAllStates())
            {
                RegExpState initialState;
                if (object.ReferenceEquals(merged._initialState, state))
                {
                    initialState = dfa._initialState;
                }
                else if (object.ReferenceEquals(merged._finalState, state))
                {
                    initialState = dfa._finalState;
                }
                else
                {
                    initialState = new RegExpState();
                }
                dictionary.Add(state, initialState);
            }
            foreach (RegExpState state3 in dictionary.Keys)
            {
                foreach (Transition transition in state3.Transitions)
                {
                    RegExpState state4 = dictionary[state3];
                    RegExpState target = dictionary[transition.Target];
                    state4.AddTransition(transition.Copy(target));
                }
            }
            return(dfa);
        }
Exemplo n.º 2
0
        static RegExpDfa PowerOptional(RegExpDfa operand, int count)
        {
            if (count == 0)
            {
                return(null);
            }
            RegExpDfa head = new RegExpDfa(operand);

            if (head.CanReturnFromFinalState())
            {
                head = HardAnd(head, EmptyTransitionDfa);
            }
            if (head.CanReturnToInitialState())
            {
                head = HardAnd(EmptyTransitionDfa, head);
            }
            RegExpDfa dfa2 = new RegExpDfa(operand) | EmptyTransitionDfa;

            for (int i = 1; i < count; i++)
            {
                Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();
                foreach (RegExpState state in head.GetAllStates())
                {
                    RegExpState initialState;
                    if (object.ReferenceEquals(state, head._finalState))
                    {
                        initialState = dfa2._initialState;
                    }
                    else
                    {
                        initialState = new RegExpState();
                    }
                    dictionary.Add(state, initialState);
                }
                dfa2._initialState = dictionary[head._initialState];
                foreach (RegExpState state3 in dictionary.Keys)
                {
                    foreach (Transition transition in state3.Transitions)
                    {
                        RegExpState state4 = dictionary[state3];
                        RegExpState target = dictionary[transition.Target];
                        state4.AddTransition(transition.Copy(target));
                    }
                }
                dfa2._initialState.AddTransition(new EmptyTransition(dfa2._finalState));
            }
            return(dfa2);
        }
Exemplo n.º 3
0
        RegExpDfa(RegExpDfa source)
        {
            this._statesCache          = new Dictionary <RegExpDfaWave, RegExpDfaWave>();
            this._stringsToStatesCache = new RegExpStringKeyTable();
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in source.GetAllStates())
            {
                dictionary.Add(state, new RegExpState());
            }
            this._initialState = dictionary[source._initialState];
            this._finalState   = dictionary[source._finalState];
            foreach (RegExpState state2 in dictionary.Keys)
            {
                foreach (Transition transition in state2.Transitions)
                {
                    Transition transition2 = transition.Copy(dictionary[transition.Target]);
                    dictionary[state2].AddTransition(transition2);
                }
            }
        }
Exemplo n.º 4
0
        static RegExpDfa HardAnd(RegExpDfa head, RegExpDfa tail)
        {
            RegExpDfa dfa = new RegExpDfa(head);
            Dictionary <RegExpState, RegExpState> dictionary = new Dictionary <RegExpState, RegExpState>();

            foreach (RegExpState state in tail.GetAllStates())
            {
                RegExpState state2 = object.ReferenceEquals(tail._initialState, state) ? dfa._finalState : new RegExpState();
                dictionary.Add(state, state2);
            }
            dfa._finalState = dictionary[tail._finalState];
            foreach (RegExpState state3 in dictionary.Keys)
            {
                foreach (Transition transition in state3.Transitions)
                {
                    RegExpState state4 = dictionary[state3];
                    RegExpState target = dictionary[transition.Target];
                    state4.AddTransition(transition.Copy(target));
                }
            }
            return(dfa);
        }