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


C# Grammar.GetLeftRecursiveRules方法代码示例

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


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

示例1: TestIndirectRecursionLoop3

        public void TestIndirectRecursionLoop3()
        {
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "s : a ;\n" +
                "a : i b X ;\n" + // should see through i
                "b : a B ;\n" +
                "i : ;\n" +
                "d : e ;\n" +
                "e : d ;\n" );

            DecisionProbe.verbose = true; // make sure we get all error info
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );

            var leftRecursive = g.GetLeftRecursiveRules();
            var expectedRules = new HashSet<string>() { "a", "b", "d", "e" };

            Assert.IsTrue( expectedRules.SequenceEqual( ruleNames( leftRecursive ) ) );

            Assert.AreEqual(1, equeue.errors.Count);
            Message msg = equeue.errors[0];
            Assert.IsTrue(msg is LeftRecursionCyclesMessage, "expecting left recursion cycles; found " + msg.GetType().Name);
            LeftRecursionCyclesMessage cyclesMsg = (LeftRecursionCyclesMessage)msg;

            // cycle of [a, b]
            ICollection result = cyclesMsg.cycles;
            var expecting = new HashSet<string>() { "a", "b", "d", "e" };

            Assert.IsTrue( expecting.SequenceEqual( ruleNames2( result ) ) );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:31,代码来源:TestDFAConversion.cs

示例2: TestIndirectRecursionLoop

        public void TestIndirectRecursionLoop()
        {
            Grammar g = new Grammar(
                "parser grammar t;\n" +
                "s : a ;\n" +
                "a : b X ;\n" +
                "b : a B ;\n" );

            DecisionProbe.verbose = true; // make sure we get all error info
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );

            HashSet<Rule> leftRecursive = g.GetLeftRecursiveRules();
            //Set expectedRules =
            //    new HashSet() {{add("a"); add("b");}};
            var expectedRules = new HashSet<string>();
            expectedRules.Add( "a" );
            expectedRules.Add( "b" );

            Assert.IsTrue( expectedRules.SequenceEqual( ruleNames( leftRecursive ) ) );

            Assert.AreEqual(1, equeue.errors.Count);
            Message msg = equeue.errors[0];
            Assert.IsTrue(msg is LeftRecursionCyclesMessage, "expecting left recursion cycles; found " + msg.GetType().Name);
            LeftRecursionCyclesMessage cyclesMsg = (LeftRecursionCyclesMessage)msg;

            // cycle of [a, b]
            ICollection result = cyclesMsg.cycles;
            var expecting = new HashSet<string>(); //{{add("a"); add("b");}};
            expecting.Add( "a" );
            expecting.Add( "b" );
            Assert.IsTrue( expecting.SequenceEqual( ruleNames2( result ) ) );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:33,代码来源:TestDFAConversion.cs

示例3: TestimmediateLeftRecursion

 public void TestimmediateLeftRecursion()
 {
     Grammar g = new Grammar(
         "parser grammar t;\n" +
         "s : a ;\n" +
         "a : a A | B;" );
     var leftRecursive = g.GetLeftRecursiveRules();
     //Set expectedRules = new HashSet() {{add("a");}};
     var expectedRules = new HashSet<string>();
     expectedRules.Add( "a" );
     Assert.IsTrue( expectedRules.SequenceEqual( ruleNames( leftRecursive ) ) );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:TestDFAConversion.cs

示例4: TestIndirectLeftRecursion

 public void TestIndirectLeftRecursion()
 {
     Grammar g = new Grammar(
         "parser grammar t;\n" +
         "s : a ;\n" +
         "a : b | A ;\n" +
         "b : c ;\n" +
         "c : a | C ;\n" );
     var leftRecursive = g.GetLeftRecursiveRules();
     //Set expectedRules = new HashSet() {{add("a"); add("b"); add("c");}};
     var expectedRules = new HashSet<string>();
     expectedRules.Add( "a" );
     expectedRules.Add( "b" );
     expectedRules.Add( "c" );
     Assert.IsTrue( expectedRules.SequenceEqual( ruleNames( leftRecursive ) ) );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:16,代码来源:TestDFAConversion.cs

示例5: TestCycleInsideRuleDoesNotForceInfiniteRecursion

 public void TestCycleInsideRuleDoesNotForceInfiniteRecursion()
 {
     Grammar g = new Grammar(
         "parser grammar t;\n" +
         "s : a ;\n" +
         "a : (A|)+ B;\n" );
     // before I added a visitedStates thing, it was possible to loop
     // forever inside of a rule if there was an epsilon loop.
     var leftRecursive = g.GetLeftRecursiveRules();
     var expectedRules = new HashSet<Rule>();
     Assert.IsTrue( expectedRules.SequenceEqual( leftRecursive ) );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:12,代码来源:TestDFAConversion.cs


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