Пример #1
0
        /// <summary>
        /// Executes the "|" operator by creating a state from which we can 
        /// choose to move to either first NFA or the second
        /// </summary>
        /// <param name="operandStack">The operand stack to execute the operator on</param>
        public void Execute(Stack<NFAFragment> operandStack)
        {
            //Get the two operands
            NFAFragment nfa2 = operandStack.Pop();
            NFAFragment nfa1 = operandStack.Pop();

            //The new NFA fragment starts with a split state
            //The unbound states in it are those of both nfa1 and nfa2
            NFAFragment newNFA = new NFAFragment();
            newNFA.startState = new NFASplitState(nfa1.startState, nfa2.startState);
            newNFA.unboundStates = nfa1.unboundStates;
            newNFA.unboundStates.AddRange(nfa2.unboundStates);

            //Put the resultant NFA back
            operandStack.Push(newNFA);
        }
Пример #2
0
        /// <summary>
        /// Compiles the given regular expression
        /// </summary>
        /// <param name="regExp">The regular expression to parse</param>
        public Regex(string regExp)
        {
            //Initialisation
            textView = regExp;

            try
            {
                //Preprocess the regular expression and compile it into an NFA
                resNFA = NFABuilder.CreateNFA(regExp);
            }
            catch (IndexOutOfRangeException)
            {
                //Exception while creating the NFA, the regular expression must be invalid
                throw new RegexCompileException();
            }
            catch (InvalidOperationException)
            {
                throw new RegexCompileException();
            }
        }