• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Tool.Grammar类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Antlr3.Tool.Grammar的典型用法代码示例。如果您正苦于以下问题:C# Grammar类的具体用法?C# Grammar怎么用?C# Grammar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Grammar类属于Antlr3.Tool命名空间,在下文中一共展示了Grammar类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GrammarSemanticsMessage

 public GrammarSemanticsMessage( int msgID,
                       Grammar g,
                       IToken offendingToken,
                       object arg )
     : this(msgID, g, offendingToken, arg, null)
 {
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:7,代码来源:GrammarSemanticsMessage.cs


示例2: GrammarSyntaxMessage

 public GrammarSyntaxMessage( int msgID,
                             Grammar grammar,
                             IToken offendingToken,
                             RecognitionException exception )
     : this(msgID, grammar, offendingToken, null, exception)
 {
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:7,代码来源:GrammarSyntaxMessage.cs


示例3: TestMessageStringificationIsConsistent

        public void TestMessageStringificationIsConsistent()
        {
            string action = "$other.tree = null;";
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar a;\n" +
                "options { output = AST;}" +
                "otherrule\n" +
                "    : 'y' ;" +
                "rule\n" +
                "    : other=otherrule {" + action + "}\n" +
                "    ;" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates
            ActionTranslator translator = new ActionTranslator( generator,
                                                                        "rule",
                                                                        new CommonToken( ANTLRParser.ACTION, action ), 1 );
            string rawTranslation =
                translator.Translate();

            int expectedMsgID = ErrorManager.MSG_WRITE_TO_READONLY_ATTR;
            object expectedArg = "other";
            object expectedArg2 = "tree";
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg, expectedArg2 );
            string expectedMessageString = expectedMessage.ToString();
            Assert.AreEqual( expectedMessageString, expectedMessage.ToString() );
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:31,代码来源:TestMessages.cs


示例4: TreeToNFAConverter

 public TreeToNFAConverter( Grammar g, NFA nfa, NFAFactory factory, ITreeNodeStream input )
     : this(input)
 {
     this.grammar = g;
     this.nfa = nfa;
     this.factory = factory;
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:7,代码来源:TreeToNFAConverterHelper.cs


示例5: TestCompleteBuffer

        public void TestCompleteBuffer()
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "ID : 'a'..'z'+;\n" +
                "INT : '0'..'9'+;\n" +
                "SEMI : ';';\n" +
                "ASSIGN : '=';\n" +
                "PLUS : '+';\n" +
                "MULT : '*';\n" +
                "WS : ' '+;\n");
            // Tokens: 012345678901234567
            // Input:  x = 3 * 0 + 2 * 0;
            ICharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
            Interpreter lexEngine = new Interpreter(g, input);
            BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

            int i = 1;
            IToken t = tokens.LT(i);
            while (t.Type != CharStreamConstants.EndOfFile)
            {
                i++;
                t = tokens.LT(i);
            }
            tokens.LT(i++); // push it past end
            tokens.LT(i++);

            string result = tokens.ToString();
            string expecting = "x = 3 * 0 + 2 * 0;";
            Assert.AreEqual(expecting, result);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:31,代码来源:TestCommonTokenStream.cs


示例6: TestCannotHaveSpaceAfterDot

        public void TestCannotHaveSpaceAfterDot()
        {
            string action = "%x. y = z;";
            //String expecting = null;

            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            Grammar g = new Grammar(
                "grammar t;\n" +
                "options {\n" +
                "    output=template;\n" +
                "}\n" +
                "\n" +
                "a : ID {" + action + "}\n" +
                "  ;\n" +
                "\n" +
                "ID : 'a';\n" );
            AntlrTool antlr = newTool();
            CodeGenerator generator = new CodeGenerator( antlr, g, "Java" );
            g.CodeGenerator = generator;
            generator.GenRecognizer(); // forces load of templates

            int expectedMsgID = ErrorManager.MSG_INVALID_TEMPLATE_ACTION;
            object expectedArg = "%x.";
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
            checkError( equeue, expectedMessage );
        }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:28,代码来源:TestTemplates.cs


示例7: DgmlGenerator

        public DgmlGenerator(Grammar grammar)
        {
            if (grammar == null)
                throw new ArgumentNullException("grammar");

            _grammar = grammar;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:7,代码来源:DgmlGenerator.cs


示例8: ActionAnalysisLexer

 public ActionAnalysisLexer(Grammar grammar, string ruleName, GrammarAST actionAST)
     : this(new ANTLRStringStream(actionAST.Token.Text))
 {
     this.grammar = grammar;
     this.enclosingRule = grammar.GetLocallyDefinedRule(ruleName);
     this.actionToken = actionAST.Token;
     this.outerAltNum = actionAST.outerAltNum;
 }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:8,代码来源:ActionAnalysisLexerHelper.cs


示例9: TestA

 public void TestA()
 {
     Grammar g = new Grammar(
         "parser grammar t;\n" +
         "a : A C | B;" );
     string expecting =
         ".s0-A->:s1=>1" + NewLine +
         ".s0-B->:s2=>2" + NewLine;
     checkDecision( g, 1, expecting, null, null, null, null, 0 );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:10,代码来源:TestDFAConversion.cs


示例10: LeftRecursiveRuleAnalyzer

 public LeftRecursiveRuleAnalyzer(ITreeNodeStream input, Grammar g, string ruleName)
     : base(input)
 {
     this.g = g;
     this.ruleName = ruleName;
     language = (string)g.GetOption("language");
     generator = new CodeGenerator(g.Tool, g, language);
     generator.LoadTemplates(language);
     recRuleTemplates = LoadPrecRuleTemplates(g.Tool);
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:10,代码来源:LeftRecursiveRuleAnalyzer.cs


示例11: TestAB_or_AC

 public void TestAB_or_AC()
 {
     Grammar g = new Grammar(
         "parser grammar t;\n" +
         "a : A B | A C;" );
     string expecting =
         ".s0-A->.s1" + NewLine +
         ".s1-B->:s2=>1" + NewLine +
         ".s1-C->:s3=>2" + NewLine;
     checkDecision( g, 1, expecting, null, null, null, null, 0 );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:11,代码来源:TestDFAConversion.cs


示例12: TestAndPredicates

 public void TestAndPredicates()
 {
     Grammar g = new Grammar(
         "parser grammar P;\n" +
         "a : {p1}? {p1a}? A | {p2}? A ;" );
     string expecting =
         ".s0-A->.s1" + NewLine +
         ".s1-{(p1&&p1a)}?->:s2=>1" + NewLine +
         ".s1-{p2}?->:s3=>2" + NewLine;
     checkDecision( g, 1, expecting, null, null, null, null, null, 0, false );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:11,代码来源:TestSemanticPredicates.cs


示例13: TestAdjacentNotCharLoops

 public void TestAdjacentNotCharLoops()
 {
     Grammar g = new Grammar(
         "lexer grammar t;\n" +
         "A : (~'r')+ ;\n" +
         "B : (~'s')+ ;\n" );
     string expecting =
         ".s0-'r'->:s3=>2" + NewLine +
         ".s0-'s'->:s2=>1" + NewLine +
         ".s0-{'\\u0000'..'q', 't'..'\\uFFFF'}->.s1" + NewLine +
         ".s1-'r'->:s3=>2" + NewLine +
         ".s1-<EOT>->:s2=>1" + NewLine +
         ".s1-{'\\u0000'..'q', 't'..'\\uFFFF'}->.s1" + NewLine;
     checkDecision( g, 3, expecting, null );
 }
开发者ID:JSchofield,项目名称:antlrcs,代码行数:15,代码来源:TestCharDFAConversion.cs


示例14: TestBadGrammarOption

        public void TestBadGrammarOption()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue ); // unique listener per thread
            AntlrTool antlr = newTool();
            Grammar g = new Grammar( antlr,
                                    "grammar t;\n" +
                                    "options {foo=3; language=Java;}\n" +
                                    "a : 'a';\n" );

            object expectedArg = "foo";
            int expectedMsgID = ErrorManager.MSG_ILLEGAL_OPTION;
            GrammarSemanticsMessage expectedMessage =
                new GrammarSemanticsMessage( expectedMsgID, g, null, expectedArg );
            checkGrammarSemanticsError( equeue, expectedMessage );
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:16,代码来源:TestSymbolDefinitions.cs


示例15: Test3LevelImport

        public void Test3LevelImport()
        {
            ErrorQueue equeue = new ErrorQueue();
            ErrorManager.SetErrorListener( equeue );
            string slave =
                "parser grammar T;\n" +
                "a : T ;\n";
            mkdir( tmpdir );
            writeFile( tmpdir, "T.g", slave );
            string slave2 =
                "parser grammar S;\n" + // A, B, C token type order
                "import T;\n" +
                "a : S ;\n";
            mkdir( tmpdir );
            writeFile( tmpdir, "S.g", slave2 );

            string master =
                "grammar M;\n" +
                "import S;\n" +
                "a : M ;\n";
            writeFile( tmpdir, "M.g", master );
            AntlrTool antlr = newTool( new string[] { "-lib", tmpdir } );
            CompositeGrammar composite = new CompositeGrammar();
            Grammar g = new Grammar( antlr, tmpdir + "/M.g", composite );
            composite.SetDelegationRoot( g );
            g.ParseAndBuildAST();
            g.composite.AssignTokenTypes();
            g.composite.DefineGrammarSymbols();

            string expectedTokenIDToTypeMap = "[M=6, S=5, T=4]";
            string expectedStringLiteralToTypeMap = "{}";
            string expectedTypeToTokenList = "[T, S, M]";

            assertEquals( expectedTokenIDToTypeMap,
                         realElements( g.composite.tokenIDToTypeMap ).ToElementString() );
            assertEquals( expectedStringLiteralToTypeMap, g.composite.stringLiteralToTypeMap.ToElementString() );
            assertEquals( expectedTypeToTokenList,
                         realElements( g.composite.typeToTokenList ).ToElementString() );

            assertEquals( "unexpected errors: " + equeue, 0, equeue.errors.Count );

            bool ok =
                rawGenerateAndBuildRecognizer( "M.g", master, "MParser", null, false );
            bool expecting = true; // should be ok
            assertEquals( expecting, ok );
        }
开发者ID:bszafko,项目名称:antlrcs,代码行数:46,代码来源:TestCompositeGrammars.cs


示例16: DefineTokens

        protected internal override void DefineTokens( Grammar root )
        {
            //System.Console.Out.WriteLine( "stringLiterals=" + stringLiterals );
            //System.Console.Out.WriteLine( "tokens=" + tokens );
            //System.Console.Out.WriteLine( "aliases=" + aliases );
            //System.Console.Out.WriteLine( "aliasesReverseIndex=" + aliasesReverseIndex );

            AssignTokenIDTypes( root );

            AliasTokenIDsAndLiterals( root );

            AssignStringTypes( root );

            //System.Console.Out.WriteLine( "stringLiterals=" + stringLiterals );
            //System.Console.Out.WriteLine( "tokens=" + tokens );
            //System.Console.Out.WriteLine( "aliases=" + aliases );
            DefineTokenNamesAndLiteralsInGrammar( root );
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:18,代码来源:AssignTokenTypesBehavior.cs


示例17: FindNode

 public virtual CompositeGrammarTree FindNode( Grammar g )
 {
     if ( g == null )
     {
         return null;
     }
     if ( this.grammar == g )
     {
         return this;
     }
     CompositeGrammarTree n = null;
     for ( int i = 0; n == null && children != null && i < children.Count; i++ )
     {
         CompositeGrammarTree child = children[i];
         n = child.FindNode( g );
     }
     return n;
 }
开发者ID:bszafko,项目名称:antlrcs,代码行数:18,代码来源:CompositeGrammarTree.cs


示例18: Stats

        internal virtual void Stats(Grammar g, StringBuilder buf)
        {
            int numDec = g.NumberOfDecisions;
            for (int decision = 1; decision <= numDec; decision++)
            {
                Grammar.Decision d = g.GetDecision(decision);
                if (d.dfa == null)
                { // unusued decisions in auto synpreds
                    //System.err.println("no decision "+decision+" dfa for "+d.blockAST.toStringTree());
                    continue;
                }
                int k = d.dfa.MaxLookaheadDepth;
                Rule enclosingRule = d.dfa.NFADecisionStartState.enclosingRule;
                if (enclosingRule.IsSynPred)
                    continue; // don't count synpred rules
                buf.Append(g.name + "." + enclosingRule.Name + ":" +
                           "");
                GrammarAST decisionAST =
                    d.dfa.NFADecisionStartState.associatedASTNode;
                buf.Append(decisionAST.Line);
                buf.Append(":");
                buf.Append(decisionAST.CharPositionInLine);
                buf.Append(" decision " + decision + ":");

                if (d.dfa.IsCyclic)
                    buf.Append(" cyclic");
                if (k != int.MaxValue)
                    buf.Append(" k=" + k); // fixed, no sempreds
                if (d.dfa.HasSynPred)
                    buf.Append(" backtracks"); // isolated synpred not gated
                if (d.dfa.HasSemPred)
                    buf.Append(" sempred"); // user-defined sempred
                //			else {
                //				buf.append("undefined");
                //				FASerializer serializer = new FASerializer(g);
                //				String result = serializer.serialize(d.dfa.startState);
                //				System.err.println(result);
                //			}
                buf.AppendLine();
            }
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:41,代码来源:GrammarReport2.cs


示例19: Test2ndToken

        public void Test2ndToken()
        {
            Grammar g = new Grammar(
                "lexer grammar t;\n" +
                "ID : 'a'..'z'+;\n" +
                "INT : '0'..'9'+;\n" +
                "SEMI : ';';\n" +
                "ASSIGN : '=';\n" +
                "PLUS : '+';\n" +
                "MULT : '*';\n" +
                "WS : ' '+;\n");
            // Tokens: 012345678901234567
            // Input:  x = 3 * 0 + 2 * 0;
            ICharStream input = new ANTLRStringStream("x = 3 * 0 + 2 * 0;");
            Interpreter lexEngine = new Interpreter(g, input);
            BufferedTokenStream tokens = new BufferedTokenStream(lexEngine);

            string result = tokens.LT(2).Text;
            string expecting = " ";
            Assert.AreEqual(expecting, result);
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:21,代码来源:TestCommonTokenStream.cs


示例20: DOTGenerator

 /** This aspect is associated with a grammar */
 public DOTGenerator( Grammar grammar )
 {
     this.grammar = grammar;
     this.dfaTemplateDirectoryName = Path.Combine(AntlrTool.ToolPathRoot, @"Tool\Templates\dot");
 }
开发者ID:bszafko,项目名称:antlrcs,代码行数:6,代码来源:DOTGenerator.cs



注:本文中的Antlr3.Tool.Grammar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Tool.GrammarAST类代码示例发布时间:2022-05-24
下一篇:
C# ST.StringTemplateGroup类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap