本文整理汇总了C#中Antlr3.Tool.Grammar.ImportTokenVocabulary方法的典型用法代码示例。如果您正苦于以下问题:C# Antlr3.Tool.Grammar.ImportTokenVocabulary方法的具体用法?C# Antlr3.Tool.Grammar.ImportTokenVocabulary怎么用?C# Antlr3.Tool.Grammar.ImportTokenVocabulary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Antlr3.Tool.Grammar
的用法示例。
在下文中一共展示了Antlr3.Tool.Grammar.ImportTokenVocabulary方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: TestTokensRules
public void TestTokensRules()
{
Grammar pg = new Grammar(
"parser grammar p;\n" +
"a : (INT|FLOAT|WS)+;\n" );
Grammar g = new Grammar();
g.ImportTokenVocabulary( pg );
g.FileName = "<string>";
g.SetGrammarContent(
"lexer grammar t;\n" +
"INT : (DIGIT)+ ;\n" +
"FLOAT : (DIGIT)+ '.' (DIGIT)* ;\n" +
"fragment DIGIT : '0'..'9';\n" +
"WS : (' ')+ {channel=99;};\n" );
ICharStream input = new ANTLRStringStream( "123 139.52" );
Interpreter lexEngine = new Interpreter( g, input );
CommonTokenStream tokens = new CommonTokenStream( lexEngine );
tokens.LT(5); // make sure it grabs all tokens
string result = tokens.ToString();
//System.out.println(result);
string expecting = "123 139.52";
Assert.AreEqual( expecting, result );
}
示例3: TestSimpleParse
public void TestSimpleParse()
{
Grammar pg = new Grammar(
"parser grammar p;\n" +
"prog : WHILE ID LCURLY (assign)* RCURLY EOF;\n" +
"assign : ID ASSIGN expr SEMI ;\n" +
"expr : INT | FLOAT | ID ;\n");
Grammar g = new Grammar();
g.ImportTokenVocabulary(pg);
g.FileName = Grammar.IGNORE_STRING_IN_GRAMMAR_FILE_NAME + "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=1; 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 1) ;) (assign y = (expr 3.42) ;) (assign z = (expr y) ;) } <EOF>))";
Assert.AreEqual(expecting, result);
}