private void Push(char input) { State s0 = new State(); State s1 = new State(); s0.AddTransition(input, s1); FSATable nfaTable = new FSATable(); nfaTable.AppendState(s0); nfaTable.AppendState(s1); mOperandStack.Add(nfaTable); mInputSet.Add(input); }
private void ConvertNFAtoDFA() { mDFATable = new FSATable(); if (mNFATable.GetStates().Count == 0) { return; } State.mStateIDCounter = 0; HashSet <State> dfaStartStates; EpsilonClosure(out dfaStartStates, mNFATable.GetFirstState()); State dfaStartState = new State(dfaStartStates); mDFATable.AppendState(dfaStartState); List <State> unmarkedDFAStates = new List <State>(); unmarkedDFAStates.Add(dfaStartState); while (unmarkedDFAStates.Count != 0) { State processingDFAState = unmarkedDFAStates[unmarkedDFAStates.Count - 1]; unmarkedDFAStates.RemoveAt(unmarkedDFAStates.Count - 1); foreach (char c in mInputSet) { HashSet <State> moveResult, epsilonClosureResult; Move(c, out moveResult, new HashSet <State>(processingDFAState.mNFAStates)); EpsilonClosure(out epsilonClosureResult, moveResult); bool found = false; State s = null; for (int i = 0; i < mDFATable.GetStates().Count; ++i) { s = mDFATable.GetState(i); if (s.mNFAStates.SetEquals(epsilonClosureResult)) { found = true; break; } } if (found == false) { State u = new State(epsilonClosureResult); unmarkedDFAStates.Add(u); mDFATable.AppendState(u); processingDFAState.AddTransition(c, u); } else { processingDFAState.AddTransition(c, s); } } } }