Ejemplo n.º 1
0
        /// <summary>
        /// Finds a unique character transition if one exists. The
        /// transition must be the only matching single character
        /// transition and no other transitions may reach the same
        /// state.
        /// </summary>
        /// <param name="ch">The character to search for</param>
        /// <returns>
        /// The unique transition state found, or null if none was found
        /// </returns>
        private NFAState FindUniqueCharTransition(char ch)
        {
            NFATransition res = null;

            foreach (var trans in this.outgoing)
            {
                if (trans.Match(ch) && trans is NFACharTransition)
                {
                    if (res != null)
                    {
                        return(null);
                    }

                    res = trans;
                }
            }

            if (res == null)
            {
                return(null);
            }

            foreach (var trans in this.outgoing)
            {
                if (trans != res && trans.State == res.State)
                {
                    return(null);
                }
            }

            return(res?.State);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a new outgoing transition.
        /// </summary>
        /// <param name="trans">The transition to add</param>
        /// <returns>The transition target state</returns>
        public NFAState AddOut(NFATransition trans)
        {
            this.outgoing.Add(trans);

            if (trans is NFAEpsilonTransition)
            {
                this.epsilonOut = true;
            }

            return(trans.State);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Adds a new incoming transition.
 /// </summary>
 /// <param name="trans">The transition to add</param>
 public void AddIn(NFATransition trans)
 {
     this.incoming.Add(trans);
 }