示例#1
0
 /// <summary>
 /// Add new state, this method check if the
 /// state <see cref="T"/> exists, if not
 /// add the state.
 /// </summary>
 /// <param name="state"></param>
 public void AddState(NfaState <Q> state)
 {
     if (!IsExists(state.Id))
     {
         if (state.StateType == StateType.StartState)
         {
             CurrentStates.Add(state);
         }
         States.Add(state);
     }
 }
示例#2
0
        private void PopChoice()
        {
            CurrentStates[0].ClearState();
            CurrentStates.Clear();
            if (_statesStack.Count == 0)
            {
                throw new Exception("Choice stack is empty. Unable to fallback to another state.");
            }

            StateMemento memento = _statesStack.Pop();

            _inx  = memento.TokenIndex;
            _move = memento.Move + 1;
            CurrentStates.Add(memento.State);
        }
示例#3
0
        public void PerformStep()
        {
            ProcessedWord += Word[CurrentPosition];

            char symbol = Word[CurrentPosition];

            var possibleNextStates = new List <State>();

            foreach (var state in CurrentStates)
            {
                var nextStates = state.PossibleNextStates
                                 .Where(x => x.Value.Invoke(symbol))
                                 .Select(pair => pair.Key);

                nextStates
                .ForEach(s => possibleNextStates.Add(s));
            }


            CurrentStates.Clear();

            foreach (var state in possibleNextStates)
            {
                CurrentStates.Add(state);
            }

            //foreach (var state in CurrentStates)
            //{
            //    for (int i = 0; i < StateTraces.Count; i++)
            //    {
            //        var trace = StateTraces[i];
            //        var brandNewTrace = new StateTrace(trace);
            //        brandNewTrace.Add(state);

            //        if (!StateTraces.Contains(brandNewTrace))
            //            StateTraces.Add(trace);
            //    }
            //}

            CurrentPosition++;
        }
示例#4
0
        /// <summary>
        /// Set state type
        /// </summary>
        /// <param name="key">The state key</param>
        /// <param name="type">The type to  be set</param>
        public void SetStateType(Q key, StateType type)
        {
            NfaState <Q> state = null;

            if ((state = GetState(key)) != null)
            {
                state.StateType = type;
                if (state.StateType == StateType.StartState)
                {
                    CurrentStates.Add(state);
                }
                else
                {
                    CurrentStates.RemoveState(key);
                }
            }
            else
            {
                throw new Exception("State doesn't exists");
            }
        }