當前位置: 首頁>>代碼示例>>C#>>正文


C# Antlr3.Tool.Grammar.GetTokenType方法代碼示例

本文整理匯總了C#中Antlr3.Tool.Grammar.GetTokenType方法的典型用法代碼示例。如果您正苦於以下問題:C# Antlr3.Tool.Grammar.GetTokenType方法的具體用法?C# Antlr3.Tool.Grammar.GetTokenType怎麽用?C# Antlr3.Tool.Grammar.GetTokenType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Antlr3.Tool.Grammar的用法示例。


在下文中一共展示了Antlr3.Tool.Grammar.GetTokenType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: TestMultAltLoop

 public void TestMultAltLoop()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : ('0'..'9'|'a'|'b')+ ;\n" );
     int Atype = g.GetTokenType( "A" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "a" ) );
     IToken result = engine.Scan( "A" );
     engine = new Interpreter( g, new ANTLRStringStream( "a" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "1234" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "aaa" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "aaaa9" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "b" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "baa" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
 }
開發者ID:JSchofield,項目名稱:antlrcs,代碼行數:27,代碼來源:TestInterpretedLexing.cs

示例3: TestSingleRuleRef

 public void TestSingleRuleRef()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : 'a' B 'c' ;\n" +
             "B : 'b' ;\n" );
     int Atype = g.GetTokenType( "A" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "abc" ) ); // should ignore the x
     IToken result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
 }
開發者ID:JSchofield,項目名稱:antlrcs,代碼行數:11,代碼來源:TestInterpretedLexing.cs

示例4: TestSimpleLoops

 public void TestSimpleLoops()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : ('0'..'9')+ '.' ('0'..'9')* | ('0'..'9')+ ;\n" );
     int Atype = g.GetTokenType( "A" );
     ICharStream input = new ANTLRStringStream( "1234.5" );
     Interpreter engine = new Interpreter( g, input );
     IToken result = engine.Scan( "A" );
     Assert.AreEqual( Atype, result.Type );
 }
開發者ID:JSchofield,項目名稱:antlrcs,代碼行數:11,代碼來源:TestInterpretedLexing.cs

示例5: TestSimpleLoop

 public void TestSimpleLoop()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "INT : (DIGIT)+ ;\n" +
             "fragment DIGIT : '0'..'9';\n" );
     int INTtype = g.GetTokenType( "INT" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "12x" ) ); // should ignore the x
     IToken result = engine.Scan( "INT" );
     Assert.AreEqual( result.Type, INTtype );
     engine = new Interpreter( g, new ANTLRStringStream( "1234" ) );
     result = engine.Scan( "INT" );
     Assert.AreEqual( result.Type, INTtype );
 }
開發者ID:JSchofield,項目名稱:antlrcs,代碼行數:14,代碼來源:TestInterpretedLexing.cs

示例6: TestSimpleAltCharTest

 public void TestSimpleAltCharTest()
 {
     Grammar g = new Grammar(
             "lexer grammar t;\n" +
             "A : 'a' | 'b' | 'c';" );
     int Atype = g.GetTokenType( "A" );
     Interpreter engine = new Interpreter( g, new ANTLRStringStream( "a" ) );
     engine = new Interpreter( g, new ANTLRStringStream( "b" ) );
     IToken result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
     engine = new Interpreter( g, new ANTLRStringStream( "c" ) );
     result = engine.Scan( "A" );
     Assert.AreEqual( result.Type, Atype );
 }
開發者ID:JSchofield,項目名稱:antlrcs,代碼行數:14,代碼來源:TestInterpretedLexing.cs

示例7: 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);
        }
開發者ID:mahanteshck,項目名稱:antlrcs,代碼行數:35,代碼來源:TestInterpretedParsing.cs


注:本文中的Antlr3.Tool.Grammar.GetTokenType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。