/** * Parses a regular expression. This method handles the Expr * production in the grammar (see regexp.grammar). * * @param start the initial NFA state * * @return the terminating NFA state * * @throws RegExpException if an error was encountered in the * pattern string */ private NFAState ParseExpr(NFAState start) { NFAState end = new NFAState(); NFAState subStart; NFAState subEnd; do { if (PeekChar(0) == '|') { ReadChar('|'); } subStart = new NFAState(); subEnd = ParseTerm(subStart); if (subStart.incoming.Length == 0) { subStart.MergeInto(start); } else { start.AddOut(new NFAEpsilonTransition(subStart)); } if (subEnd.outgoing.Length == 0 || (!end.HasTransitions() && PeekChar(0) != '|')) { subEnd.MergeInto(end); } else { subEnd.AddOut(new NFAEpsilonTransition(end)); } } while (PeekChar(0) == '|'); return(end); }
/** * Parses a regular expression. This method handles the Expr * production in the grammar (see regexp.grammar). * * @param start the initial NFA state * * @return the terminating NFA state * * @throws RegExpException if an error was encountered in the * pattern string */ private NFAState ParseExpr(NFAState start) { NFAState end = new NFAState(); NFAState subStart; NFAState subEnd; do { if (PeekChar(0) == '|') { ReadChar('|'); } subStart = new NFAState(); subEnd = ParseTerm(subStart); if (subStart.incoming.Length == 0) { subStart.MergeInto(start); } else { start.AddOut(new NFAEpsilonTransition(subStart)); } if (subEnd.outgoing.Length == 0 || (!end.HasTransitions() && PeekChar(0) != '|')) { subEnd.MergeInto(end); } else { subEnd.AddOut(new NFAEpsilonTransition(end)); } } while (PeekChar(0) == '|'); return end; }