protected internal override NFATable GenNFATable(int[] map, List <char[]> revMap) { NFATable ret = new NFATable(map, revMap); ret.AddState(); ret.SetStateFinal(1); ret.AddTransition(0, 1, set); return(ret); }
/// <summary> /// Copy this NFATable. /// Notice that the new NFATable has no final state. /// </summary> /// <returns> A new NFATable. </returns> private NFATable Copy() { NFATable ret = new NFATable(map, revMap); // Add the first nfa. // Starts from 1 to avoid two 0 state. for (int i = 1; i < table.Count(); ++i) { ret.AddState(); } for (int from = 0; from < table.Count(); ++from) { for (int i = 0; i < table[from].Count(); ++i) { ret.table[from][i] = new HashSet <int>(table[from][i]); } } return(ret); }
/// <summary> /// Match one or more. /// </summary> /// <returns> A new NFATable. </returns> public NFATable Ques() { NFATable nfa = new NFATable(map, revMap); nfa.AddState(); nfa.AddEpsilonTransition(0, 1); NFATable ret = nfa.Merge(this); ret.AddEpsilonTransition(0, 2); ret.SetStateFinal(1); int offset = 2; foreach (int final in finals) { ret.AddEpsilonTransition(final + offset, 1); } return(ret); }
/// <summary> /// Merge this nfa with another one /// by adding their states at the end of the table. /// Notice that the new NFATable has no final state. /// </summary> /// <param name="other"> NFATable to be merged. </param> /// <returns> The new merged NFATable. </returns> private NFATable Merge(NFATable other) { NFATable ret = Copy(); // Add the second nfa. int offset = ret.table.Count(); for (int i = 0; i < other.table.Count(); ++i) { ret.AddState(); } for (int from = 0; from < other.table.Count(); ++from) { for (int i = 0; i < other.table[from].Count(); ++i) { foreach (int to in other.table[from][i]) { ret.table[from + offset][i].Add(to + offset); } } } return(ret); }