本文整理汇总了C#中Antlr3.Tool.Grammar类的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Tool.Grammar类的具体用法?C# Antlr3.Tool.Grammar怎么用?C# Antlr3.Tool.Grammar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Antlr3.Tool.Grammar类属于命名空间,在下文中一共展示了Antlr3.Tool.Grammar类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestMismatchedSetError
public void TestMismatchedSetError()
{
Grammar pg = new Grammar(
"parser grammar p;\n" +
"prog : WHILE ID LCURLY (assign)* RCURLY;\n" +
"assign : ID ASSIGN expr SEMI ;\n" +
"expr : INT | FLOAT | ID ;\n");
Grammar g = new Grammar();
g.ImportTokenVocabulary(pg);
g.FileName = "<string>";
g.SetGrammarContent(
"lexer grammar t;\n" +
"WHILE : 'while';\n" +
"LCURLY : '{';\n" +
"RCURLY : '}';\n" +
"ASSIGN : '=';\n" +
"SEMI : ';';\n" +
"ID : ('a'..'z')+ ;\n" +
"INT : (DIGIT)+ ;\n" +
"FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n" +
"fragment DIGIT : '0'..'9';\n" +
"WS : (' ')+ ;\n");
ICharStream input = new ANTLRStringStream("while x { i=; y=3.42; z=y; }");
Interpreter lexEngine = new Interpreter(g, input);
FilteringTokenStream tokens = new FilteringTokenStream(lexEngine);
tokens.SetTokenTypeChannel(g.GetTokenType("WS"), 99);
//System.out.println("tokens="+tokens.toString());
Interpreter parseEngine = new Interpreter(pg, tokens);
ParseTree t = parseEngine.Parse("prog");
string result = t.ToStringTree();
string expecting =
"(<grammar p> (prog while x { (assign i = (expr MismatchedSetException(10!={5,6,7})))))";
Assert.AreEqual(expecting, result);
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:35,代码来源:TestInterpretedParsing.cs
示例2: NFAConversionThread
public NFAConversionThread( Grammar grammar,
Barrier barrier,
int i,
int j )
{
this.grammar = grammar;
this.barrier = barrier;
this.i = i;
this.j = j;
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:10,代码来源:NFAConversionThread.cs
示例3: TestCharOptional
public void TestCharOptional()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : 'a'?;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (? (BLOCK (ALT 'a' <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:10,代码来源:TestASTConstruction.cs
示例4: TestA
public void TestA()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : A;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT A <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:10,代码来源:TestASTConstruction.cs
示例5: ActionTranslator
public ActionTranslator( CodeGenerator generator,
string ruleName,
GrammarAST actionAST )
: this(new ANTLRStringStream( actionAST.Token.Text ))
{
this.generator = generator;
this.grammar = generator.grammar;
this.enclosingRule = grammar.GetLocallyDefinedRule( ruleName );
this.actionToken = actionAST.Token;
this.outerAltNum = actionAST.outerAltNum;
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:11,代码来源:ActionTranslatorHelper.cs
示例6: TestActionInStarLoop
public void TestActionInStarLoop()
{
Grammar g = new Grammar(
"grammar Expr;\n" +
"options { backtrack=true; }\n" +
"a : ({blort} 'x')* ;\n" ); // bug: the synpred had nothing in it
string expecting =
"(rule synpred1_Expr ARG RET scope (BLOCK (ALT blort 'x' <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "synpred1_Expr" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:11,代码来源:TestASTConstruction.cs
示例7: TestA
public void TestA()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : A;" );
string expecting =
".s0->.s1\n" +
".s1->.s2\n" +
".s2-A->.s3\n" +
".s3->:s4\n" +
":s4-EOF->.s5\n";
checkRule( g, "a", expecting );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:13,代码来源:TestNFAConstruction.cs
示例8: TestA
public void TestA()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : A;" );
string expecting =
".s0->.s1" + NewLine +
".s1->.s2" + NewLine +
".s2-A->.s3" + NewLine +
".s3->:s4" + NewLine +
":s4-EOF->.s5" + NewLine;
checkRule( g, "a", expecting );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:13,代码来源:TestNFAConstruction.cs
示例9: 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 );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:13,代码来源:TestDFAMatching.cs
示例10: PerformGrammarAnalysis
protected override void PerformGrammarAnalysis(CodeGenerator generator, Grammar grammar)
{
base.PerformGrammarAnalysis(generator, grammar);
foreach (Rule rule in grammar.Rules)
rule.ThrowsSpec.Add("RecognitionException");
IEnumerable<Rule> delegatedRules = grammar.GetDelegatedRules();
if (delegatedRules != null)
{
foreach (Rule rule in delegatedRules)
rule.ThrowsSpec.Add("RecognitionException");
}
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:14,代码来源:JavaTarget.cs
示例11: 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 );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:14,代码来源:TestDFAMatching.cs
示例12: Test2InsertMiddleIndex
public void Test2InsertMiddleIndex()
{
Grammar g = new Grammar(
"lexer grammar t;\n" +
"A : 'a';\n" +
"B : 'b';\n" +
"C : 'c';\n" );
ICharStream input = new ANTLRStringStream( "abc" );
Interpreter lexEngine = new Interpreter( g, input );
TokenRewriteStream tokens = new TokenRewriteStream( lexEngine );
tokens.Fill();
tokens.InsertBefore( 1, "x" );
tokens.InsertBefore( 1, "y" );
string result = tokens.ToString();
string expecting = "ayxbc";
Assert.AreEqual( expecting, result );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:17,代码来源:TestTokenRewriteStream.cs
示例13: TestRuleListLabelOfPositiveClosure
public void TestRuleListLabelOfPositiveClosure()
{
Grammar g = new Grammar(
"grammar P;\n" +
"options {output=AST;}\n" +
"a : x+=b+;\n" +
"b : ID;\n" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (+= x b) <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:12,代码来源:TestASTConstruction.cs
示例14: TestNakeRulePlusInLexer
public void TestNakeRulePlusInLexer()
{
Grammar g = new Grammar(
"lexer grammar P;\n" +
"A : B+;\n" +
"B : 'a';" );
string expecting =
"(rule A ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT B <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "A" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:11,代码来源:TestASTConstruction.cs
示例15: TestNakedRuleOptional
public void TestNakedRuleOptional()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : b?;\n" +
"b : B;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (? (BLOCK (ALT b <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:11,代码来源:TestASTConstruction.cs
示例16: TestListLabelOfClosure2
public void TestListLabelOfClosure2()
{
Grammar g = new Grammar(
"grammar P;\n" +
"a : x+='int'*;" );
string expecting =
"(rule a ARG RET scope (BLOCK (ALT (* (BLOCK (ALT (+= x 'int') <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "a" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:10,代码来源:TestASTConstruction.cs
示例17: TestCharRangePlus
public void TestCharRangePlus()
{
Grammar g = new Grammar(
"lexer grammar P;\n" +
"ID : 'a'..'z'+;" );
string expecting =
"(rule ID ARG RET scope (BLOCK (ALT (+ (BLOCK (ALT (.. 'a' 'z') <end-of-alt>) <end-of-block>)) <end-of-alt>) <end-of-block>) <end-of-rule>)";
string found = g.GetRule( "ID" ).tree.ToStringTree();
assertEquals( expecting, found );
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:10,代码来源:TestASTConstruction.cs
示例18: TestLabeledNotSet
public void TestLabeledNotSet()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"tokens { A; B; C; }\n" +
"a : t=~A ;\n" );
string expecting =
".s0->.s1" + NewLine +
".s1->.s2" + NewLine +
".s2-B..C->.s3" + NewLine +
".s3->:s4" + NewLine +
":s4-EOF->.s5" + NewLine;
checkRule( g, "a", expecting );
string expectingGrammarStr =
"1:8: parser grammar P;\n" +
"a : t=~ A ;";
Assert.AreEqual( expectingGrammarStr, g.ToString() );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:19,代码来源:TestNFAConstruction.cs
示例19: Init
public void Init( Grammar g )
{
this.grammar = g;
this.generator = grammar.CodeGenerator;
this.templates = generator.Templates;
}
开发者ID:bszafko,项目名称:antlrcs,代码行数:6,代码来源:CodeGenTreeWalkerHelper.cs
示例20: TestNakedAoptional
public void TestNakedAoptional()
{
Grammar g = new Grammar(
"parser grammar P;\n" +
"a : A?;" );
string expecting =
".s0->.s1" + NewLine +
".s1->.s2" + NewLine +
".s2->.s3" + NewLine +
".s2->.s8" + NewLine +
".s3-A->.s4" + NewLine +
".s4->.s5" + NewLine +
".s5->:s6" + NewLine +
".s8->.s5" + NewLine +
":s6-EOF->.s7" + NewLine;
checkRule( g, "a", expecting );
}
开发者ID:JSchofield,项目名称:antlrcs,代码行数:17,代码来源:TestNFAConstruction.cs
注:本文中的Antlr3.Tool.Grammar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论