private NFA parseRegex(String str, ref int loc) { NFA builtNFA = new NFA(""); while (loc < str.Length) { NFA nextNFA = parseOne(str, ref loc); builtNFA = builtNFA.conc(nextNFA); } return(builtNFA); }
private NFA parseParenthesis(string str, ref int loc) { //str[loc] == '(' loc++; NFA totalNFA = null; NFA builtNFA = null; while (str[loc] != ')') { if (loc >= str.Length) { throw new RegexException("Regex has a ( without a matching )"); } if (str[loc] == '|') { if (totalNFA == null) { totalNFA = builtNFA; } else { totalNFA = totalNFA.or(builtNFA); } builtNFA = null; loc++; } NFA nextNFA = parseOne(str, ref loc); if (builtNFA == null) { builtNFA = nextNFA; } else { builtNFA = builtNFA.conc(nextNFA); } } if (totalNFA == null) { totalNFA = builtNFA; } else { totalNFA = totalNFA.or(builtNFA); } loc++; //loc is first character after ) return(totalNFA); }