本文整理汇总了C#中Antlr3.Tool.Grammar.BuildNFA方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Tool.Grammar.BuildNFA方法的具体用法?C# Antlr3.Tool.Grammar.BuildNFA怎么用?C# Antlr3.Tool.Grammar.BuildNFA使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Tool.Grammar
的用法示例。
在下文中一共展示了Antlr3.Tool.Grammar.BuildNFA方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFiniteCommonLeftPrefixes
public void TestFiniteCommonLeftPrefixes()
{
Grammar g = new Grammar(
"lexer grammar t;\n" +
"A : 'a' 'b' | 'a' 'c' | 'd' 'e' ;" );
g.BuildNFA();
g.CreateLookaheadDFAs( false );
DFA dfa = g.GetLookaheadDFA( 1 );
checkPrediction( dfa, "ab", 1 );
checkPrediction( dfa, "ac", 2 );
checkPrediction( dfa, "de", 3 );
checkPrediction( dfa, "q", NFA.INVALID_ALT_NUMBER );
}
示例2: TestSets
public void TestSets()
{
Grammar g = new Grammar(
"lexer grammar t;\n" +
"A : {;}'a'..'z' | ';' | '0'..'9' ;" );
g.BuildNFA();
g.CreateLookaheadDFAs( false );
DFA dfa = g.GetLookaheadDFA( 1 );
checkPrediction( dfa, "a", 1 );
checkPrediction( dfa, "q", 1 );
checkPrediction( dfa, "z", 1 );
checkPrediction( dfa, ";", 2 );
checkPrediction( dfa, "9", 3 );
}
示例3: checkRule
private void checkRule( Grammar g, string rule, string expecting )
{
g.BuildNFA();
State startState = g.GetRuleStartState( rule );
FASerializer serializer = new FASerializer( g );
string result = serializer.Serialize( startState );
//System.out.print(result);
Assert.AreEqual( expecting, result );
}
示例4: PerformGrammarAnalysis
protected internal virtual void PerformGrammarAnalysis( CodeGenerator generator,
Grammar grammar )
{
// Build NFAs from the grammar AST
grammar.BuildNFA();
// Create the DFA predictors for each decision
grammar.CreateLookaheadDFAs();
}
示例5: TestSimpleAltCharTest
public void TestSimpleAltCharTest()
{
Grammar g = new Grammar(
"lexer grammar t;\n" +
"A : {;}'a' | 'b' | 'c';" );
g.BuildNFA();
g.CreateLookaheadDFAs( false );
DFA dfa = g.GetLookaheadDFA( 1 );
checkPrediction( dfa, "a", 1 );
checkPrediction( dfa, "b", 2 );
checkPrediction( dfa, "c", 3 );
checkPrediction( dfa, "d", NFA.INVALID_ALT_NUMBER );
}
示例6: TestSimpleLoops
public void TestSimpleLoops()
{
Grammar g = new Grammar(
"lexer grammar t;\n" +
"A : (DIGIT)+ '.' DIGIT | (DIGIT)+ ;\n" +
"fragment DIGIT : '0'..'9' ;\n" );
g.BuildNFA();
g.CreateLookaheadDFAs( false );
DFA dfa = g.GetLookaheadDFA( 3 );
checkPrediction( dfa, "32", 2 );
checkPrediction( dfa, "999.2", 1 );
checkPrediction( dfa, ".2", NFA.INVALID_ALT_NUMBER );
}