/// <summary> /// Executes the "?" operator by creating a split state that allows to either /// go through the NFA or not. /// </summary> /// <param name="operandStack">The operand stack to execute the operator on</param> public void Execute(Stack<NFAFragment> operandStack) { //Pop the needed NFA NFAFragment nfa1 = operandStack.Pop(); //Create the split state NFASplitState splitState = new NFASplitState(nfa1.startState, null); //The beginning of the NFA is now the split state nfa1.startState = splitState; //Add the split state to the list of unbound states nfa1.unboundStates.Add(splitState); //Push the resultant NFA into stack operandStack.Push(nfa1); }
/// <summary> /// Executes the "*" operator by creating a split state which allows to either go through the NFA or continue /// The exits from the NFA will lead back to this state /// Result - zero or more of the NFA /// The only difference from the Plus is that the split is before the NFA. /// </summary> /// <param name="operandStack">The operand stack to execute the operator on</param> public void Execute(Stack<NFAFragment> operandStack) { //Pop the needed NFA from the stack NFAFragment nfa1 = operandStack.Pop(); //Create the split state NFASplitState splitState = new NFASplitState(nfa1.startState, null); //Make the split state the beginning of the NFA nfa1.startState = splitState; //Connect the exits from the NFA with the split state nfa1.ConnectUnboundStates(splitState); //The only unbound state now is the split state nfa1.unboundStates.Clear(); nfa1.unboundStates.Add(splitState); //Push the resultant NFA back operandStack.Push(nfa1); }
/// <summary> /// Executes the "+" operator by creating an NFA that consists of the original NFA, the outputs from which // go to a split state which gives an option of going back to the same NFA. // Result - accepts one or more of the given NFA. /// </summary> /// <param name="operandStack">The operand stack to execute the operator on</param> public void Execute(Stack<NFAFragment> operandStack) { //Get the needed NFA fragment NFAFragment nfa1 = operandStack.Pop(); //Create the split state, with the possibility to return to the original NFA NFASplitState splitState = new NFASplitState(nfa1.startState, null); //Connect all exits in the original NFA to the created state nfa1.ConnectUnboundStates(splitState); //The only unbound state now is the split state nfa1.unboundStates.Clear(); nfa1.unboundStates.Add(splitState); //Push the resultant NFA back operandStack.Push(nfa1); }