当前位置: 首页>>代码示例>>C#>>正文


C# Converter.convertToDFA方法代码示例

本文整理汇总了C#中Converter.convertToDFA方法的典型用法代码示例。如果您正苦于以下问题:C# Converter.convertToDFA方法的具体用法?C# Converter.convertToDFA怎么用?C# Converter.convertToDFA使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Converter的用法示例。


在下文中一共展示了Converter.convertToDFA方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        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();
        }
开发者ID:realn0whereman,项目名称:MiniRE,代码行数:48,代码来源:Driver.cs

示例2: Main

        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);
            }
        }
开发者ID:realn0whereman,项目名称:ScanGen,代码行数:90,代码来源:Program.cs


注:本文中的Converter.convertToDFA方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。