Пример #1
0
        /// <summary>
        /// Performs the alternation of two NFA's
        /// </summary>
        /// <param name="nfa">NFA to be alternation</param>
        /// <returns>The alternation NFA</returns>
        public NFA <T> Or(NFA <T> nfa)
        {
            NFA <T> result    = this.Clone() as NFA <T>;
            NFA <T> orparcel  = nfa.Clone() as NFA <T>;
            int     nextavail = result.NextAvailableState;

            //first state will be reconverted (avoid state number loss)
            orparcel.OffsetStates(nextavail - 1);
            orparcel.RenumberState(orparcel.InitialState, result.InitialState);
            orparcel.RenumberState(orparcel.AcceptingStates[0], result.AcceptingStates[0]);
            result.Transitions.AddRange(orparcel.Transitions);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Performs the replacement of all Transitions given a symbol by a full NFA
        /// </summary>
        /// <param name="symbol">Generic type T value of the trigger to be replaced</param>
        /// <param name="replacement">The NFA be inserted</param>
        /// <returns>A NFA with all the replacemente in place</returns>
        public NFA <T> ReplaceTransitions(T symbol, NFA <T> replacement)
        {
            NFA <T> result = this.Clone() as NFA <T>;

            for (int i = 0; i < result.Transitions.Count; i++)
            {
                if (result.Transitions[i].Symbol.CompareTo(symbol) == 0)
                {
                    NFA <T> insert = replacement.Clone() as NFA <T>;
                    insert.OffsetStates(result.NextAvailableState);
                    insert.RenumberState(insert.InitialState, result.Transitions[i].PreviousState);
                    insert.RenumberState(insert.AcceptingStates[0], result.Transitions[i].NextState);
                    result.Transitions.AddRange(insert.Transitions);
                    result.Transitions.RemoveAt(i);
                    i--;
                }
            }

            return(result);
        }