Beispiel #1
0
        HashSet <StatePath> EpsClosure(HashSet <StatePath> prevStates)
        {
            HashSet <StatePath> closure  = new HashSet <StatePath>();
            Stack <StatePath>   dfsStack = new Stack <StatePath>();

            foreach (StatePath prevState in prevStates)
            {
                closure.Add(prevState);
                dfsStack.Push(prevState);
            }

            while (dfsStack.Count > 0)
            {
                StatePath           state     = dfsStack.Pop();
                HashSet <StatePath> adjacents = state.State.OnInput(Eps);

                var exits =
                    from adjacent in adjacents
                    where adjacent.Marked
                    select adjacent;

                foreach (var exit in exits)
                {
                    State machineFinalState = (State)exit.State;

                    machineFinalState.Parent.Captured = exit.Recorded;
                }

                foreach (StatePath adjacent in adjacents)
                {
                    adjacent.Recorded += state.Recorded;
                    if (!closure.Contains(adjacent))
                    {
                        closure.Add(adjacent);
                        dfsStack.Push(adjacent);
                    }
                }
            }

            return(closure);
        }
Beispiel #2
0
        public HashSet <StatePath> OnInput(char[] input)
        {
            HashSet <StatePath> next = new HashSet <StatePath>();

            for (int i = 0; i < inputs.Count; i++)
            {
                if (inputs[i] != input)
                {
                    continue;
                }

                var nextPath = new StatePath(transitions[i]);

                if (inputs[i] == StateMachine.EPS_EXIT)
                {
                    nextPath.Marked = true;
                }

                next.Add(nextPath);
            }
            return(next);
        }