Entry point to the Recursive Descent Parser.
Example #1
0
        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);
            }
        }
 public void MyTestInitialize()
 {
     this.testInst = new RDMain("");
     this.testInst.LineGraph = new Graph();
 }