static void Main() { string epsilon = "0"; Graph g = new Graph(); //create vertices /* BaseVertex one = g.CreateNewVertex("0",false); BaseVertex two = g.CreateNewVertex("1",false); BaseVertex three = g.CreateNewVertex("2",false); */ //BaseVertex four = g.CreateNewVertex("4",false); //BaseVertex five = g.CreateNewVertex("5",false); /* one.AddConnection(two, "a"); two.AddConnection(two, "a"); two.AddConnection(three, epsilon); three.AddConnection(three, "b"); three.AddConnection(two, "a"); three.AddConnection(one, "a"); */ BaseVertex v0 = g.CreateNewVertex("0", false); BaseVertex v1 = g.CreateNewVertex("1", true); BaseVertex v2 = g.CreateNewVertex("2", false); v0.AddConnection(v1, "a"); v1.AddConnection(v1, "a"); v1.AddConnection(v2, epsilon); v2.AddConnection(v2, "b"); v2.AddConnection(v0, "a"); v2.AddConnection(v1, "a"); String nfaDOT = g.ToDOT("NFA"); Converter c = new Converter(g,epsilon); //Console.WriteLine(); c.convertToDFA(v0); //String dfaDOT = c.table.createGraph().ToDOT("DFA"); //Console.WriteLine("Done"); //Console.ReadLine(); }
static void Main(string[] args) { //StringBuilder file = new StringBuilder(); //using (FileStream fs = new FileStream("../../../Grammar.txt", FileMode.Open)) //{ // using (StreamReader sr = new StreamReader(fs)) // { // while (!sr.EndOfStream) // { // file.AppendLine(sr.ReadLine()); // } // } //} //RDMain parser = new RDMain(file.ToString()); //Graph nfa = parser.doParse(); //nfa.AddIndividualCharacters(parser.CharacterClasses); ////convert nfa into dfa //Converter converter = new Converter(nfa, ""); //converter.convertToDFA(nfa.StartVertex); //Graph dfa = converter.table.createGraph(); //dfa.WriteTransitionTable(); //Console.ReadLine(); StringBuilder file = new StringBuilder(); Dictionary<string, string> options = new Dictionary<string, string>(); Program.doDictionarySetup(options, args); if (options["-g"] != "") // Grammar file mode { try { using (FileStream fs = new FileStream(options["-g"], FileMode.Open)) { using (StreamReader sr = new StreamReader(fs)) { while (!sr.EndOfStream) { file.AppendLine(sr.ReadLine()); } } } } catch (FileNotFoundException fnf) { Console.Error.WriteLine("Could not find grammar file."); Environment.Exit(1); } RDMain parser = new RDMain(file.ToString()); Graph nfa = parser.doParse(); nfa.AddIndividualCharacters(parser.CharacterClasses); //convert nfa into dfa Converter converter = new Converter(nfa, ""); converter.convertToDFA(nfa.StartVertex); Graph dfa = converter.table.createGraph(); if (options["-dt"] != "") { //Me: Write out the DFA table file here. dfa.SaveToFile(options["-dt"]); } else { //Me: Write DFA table to screen here. Console.WriteLine("DFA table: \n\n"); dfa.WriteTransitionTable(); } } else if (options["-tf"] != "") { if (options["-idt"] == "") { Console.Error.WriteLine("-idt cannot be left blank."); Environment.Exit(1); } Graph dfa = Graph.ReadFromFile(options["-idt"]); Program.TestInputFile(options["-tf"], dfa, options); } else { Console.WriteLine("No mode specified.\n\nUsage: program.exe (-g grammarfile.txt [-dt datatableoutputfile.txt]) (-idt dfatableinputfile.txt -tf inputtokenfile.txt)"); Environment.Exit(1); } }