/* * Function: GetNextUnmarkedDFA * Description: Returns next unmarked DFA state from spec */ public Dfa GetNextUnmarkedDFA() { int size; Dfa dfa; size = dfa_states.Count; while (unmarked_dfa < size) { dfa = (Dfa)dfa_states[unmarked_dfa]; if (!dfa.IsMarked()) { #if OLD_DUMP_DEBUG Console.Write("*"); Console.WriteLine("---------------"); Console.Write("working on DFA state " + Int32.ToString(unmarked_dfa) + " = NFA states: "); Nfa2Dfa.Print_Set(dfa.GetNFASet()); Console.WriteLine(""); #endif return(dfa); } unmarked_dfa++; } return(null); }
private static void make_dtrans(Spec s) { Console.WriteLine("Working on DFA states."); s.InitUnmarkedDFA(); int num = s.state_rules.Length; s.state_dtrans = new int[num]; for (int i = 0; i < num; i++) { Bunch bunch = new Bunch(s.state_rules[i]); bunch.e_closure(); Nfa2Dfa.add_to_dstates(s, bunch); s.state_dtrans[i] = s.dtrans_list.Count; Dfa nextUnmarkedDFA; while ((nextUnmarkedDFA = s.GetNextUnmarkedDFA()) != null) { nextUnmarkedDFA.SetMarked(); DTrans dTrans = new DTrans(s, nextUnmarkedDFA); for (int j = 0; j < s.dtrans_ncols; j++) { bunch.move(nextUnmarkedDFA, j); if (!bunch.IsEmpty()) { bunch.e_closure(); } int num2; if (bunch.IsEmpty()) { num2 = -1; } else { num2 = Nfa2Dfa.in_dstates(s, bunch); if (num2 == -1) { num2 = Nfa2Dfa.add_to_dstates(s, bunch); } } dTrans.SetDTrans(j, num2); } s.dtrans_list.Add(dTrans); } } Console.WriteLine(""); }
public static void MakeDFA(Spec s) { Nfa2Dfa.make_dtrans(s); Nfa2Dfa.free_nfa_states(s); Nfa2Dfa.free_dfa_states(s); }
public Gen(string filename, string outfile, int version) { this.init_flag = false; this.inputFilePath = Path.GetFullPath(filename); this.instream = File.OpenText(this.inputFilePath); this.outstream = new IndentedTextWriter(File.CreateText(outfile), "\t"); this.outstream.Indent = 2; this.ibuf = new Input(this.instream); this.spec = new Spec(); this.spec.Version = version; this.nfa2dfa = new Nfa2Dfa(); this.minimize = new Minimize(); this.makeNfa = new MakeNfa(); this.emit = new Emit(); this.init_flag = true; }