コード例 #1
0
        private DFAState <T> CalculateDfaState(RegEx <T> regEx)
        {
            if (dictionaryOfDfaStates.ContainsKey(regEx))
            {
                return(dictionaryOfDfaStates[regEx]); //return this state
            }
            var new_state = new DFAState <T>();

            dictionaryOfDfaStates.Add(regEx, new_state);

            var listOfTransitions = new List <KeyValuePair <T, DFAState <T> > >();

            foreach (var c in regEx.DerivChanges())
            {
                listOfTransitions.Add(new KeyValuePair <T, DFAState <T> >(c, CalculateDfaState(regEx.Derivative(c))));
            }

            if (regEx.HasEpsilon())
            {
                new_state._accepting = accepting;
            }
            else
            {
                new_state._accepting = 0;
            }

            if (listOfTransitions.Count == 0 || !listOfTransitions[0].Key.Equals(MinSymbol <T>()))
            {
                if (deadState == null)
                {
                    deadState              = new DFAState <T>();
                    deadState._accepting   = 0;
                    deadState._transitions = new KeyValuePair <T, DFAState <T> >[] { new KeyValuePair <T, DFAState <T> >(MinSymbol <T>(), deadState) };
                }
                listOfTransitions.Insert(0, new KeyValuePair <T, DFAState <T> >(MinSymbol <T>(), deadState));
                for (int i = 1; i < listOfTransitions.Count; i++)
                {
                    if (listOfTransitions[i - 1].Key.CompareTo(listOfTransitions[i].Key) >= 0)
                    {
                        throw new Exception("Inpropper order");
                    }
                }
            }

            new_state._transitions = listOfTransitions.ToArray();

            return(new_state);
        }
コード例 #2
0
 /// <summary>
 /// Create RegExDfa from RegEx
 /// </summary>
 /// <param name="regEx">Regular Expression from which is made automata</param>
 /// <param name="acceptingStateMarker">Number for accepting states</param>
 public RegExDfa(RegEx <T> regEx, uint acceptingStateMarker)
 {
     accepting = acceptingStateMarker;
     _start    = CalculateDfaState(regEx);
 }
コード例 #3
0
 /// <summary>
 /// Create RegExDfa with start state
 /// </summary>
 /// <param name="start">Start state</param>
 public RegExDfa(DFAState <T> start)
 {
     _start = start;
 }