public void AddState(FSMNode n) { n.SetFSM(this); nodes.Add(n); //if this node is the first one, set as start node if (nodes.Count == 1) { startNode.SetStartNode(n.GetType()); } }
private void TransitionToNode(System.Type t) { currentNode.Exit(); foreach (FSMNode node in nodes) { if (node.GetType() == t) { currentNode = node; break; } } currentNode.Entry(); }
public void ProcessChar(char c) { //in min mode, if we've already accepted, //then we can never accept again if (!max && IsAccepting()) { currStates.Clear(); } ISet <FSMNode> newStates = new HashSet <FSMNode> (); //we need to DFS through epsilon transitions, let's //use a stack Stack <FSMNode> epsilonClosureStack = new Stack <FSMNode> (); foreach (FSMNode state in currStates) { state.RegisterNewStatesForChar(c, delegate(FSMNode obj) { if (!newStates.Contains(obj)) { epsilonClosureStack.Push(obj); newStates.Add(obj); } }); } while (epsilonClosureStack.Count != 0) { FSMNode top = epsilonClosureStack.Pop(); foreach (FSMNode epsilonDest in top.epsilonTransitions) { if (!newStates.Contains(epsilonDest)) { epsilonClosureStack.Push(epsilonDest); newStates.Add(epsilonDest); } } } this.currStates = newStates; }
public RunnableFSM(FSMNode initialState, ISet <FSMNode> finalStates, bool max) { this.initialState = initialState; this.finalStates = finalStates; this.max = max; }
private FSM(FSMNode initialState, ISet <FSMNode> finalStates) { stale = false; this.initialState = initialState; this.finalStates = finalStates; }