本文整理汇总了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 ) ) );
}
示例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 ) ) );
}
示例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 ) ) );
}
示例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 ) ) );
}
示例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 ) );
}