当前位置: 首页>>代码示例>>C#>>正文


C# Grammar.GetDecision方法代码示例

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


在下文中一共展示了Grammar.GetDecision方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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

示例2: GetReportData

        public static ReportData GetReportData(Grammar g)
        {
            ReportData data = new ReportData();
            data.version = Version;
            data.gname = g.name;

            data.gtype = g.GrammarTypeString;

            data.language = (string)g.GetOption("language");
            data.output = (string)g.GetOption("output");
            if (data.output == null)
            {
                data.output = "none";
            }

            string k = (string)g.GetOption("k");
            if (k == null)
            {
                k = "none";
            }
            data.grammarLevelk = k;

            string backtrack = (string)g.GetOption("backtrack");
            if (backtrack == null)
            {
                backtrack = "false";
            }
            data.grammarLevelBacktrack = backtrack;

            int totalNonSynPredProductions = 0;
            int totalNonSynPredRules = 0;
            ICollection<Rule> rules = g.Rules;
            foreach (Rule r in rules)
            {
                if (!r.Name.StartsWith(Grammar.SynpredRulePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    totalNonSynPredProductions += r.NumberOfAlts;
                    totalNonSynPredRules++;
                }
            }

            data.numRules = totalNonSynPredRules;
            data.numOuterProductions = totalNonSynPredProductions;

            int numACyclicDecisions =
                g.NumberOfDecisions - g.GetNumberOfCyclicDecisions();
            List<int> depths = new List<int>();
            int[] acyclicDFAStates = new int[numACyclicDecisions];
            int[] cyclicDFAStates = new int[g.GetNumberOfCyclicDecisions()];
            int acyclicIndex = 0;
            int cyclicIndex = 0;
            int numLL1 = 0;
            int blocksWithSynPreds = 0;
            int dfaWithSynPred = 0;
            int numDecisions = 0;
            int numCyclicDecisions = 0;
            for (int i = 1; i <= g.NumberOfDecisions; i++)
            {
                Grammar.Decision d = g.GetDecision(i);
                if (d.dfa == null)
                {
                    //System.out.println("dec "+d.decision+" has no AST");
                    continue;
                }
                Rule r = d.dfa.NFADecisionStartState.enclosingRule;
                if (r.Name.StartsWith(Grammar.SynpredRulePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    //System.out.println("dec "+d.decision+" is a synpred");
                    continue;
                }

                numDecisions++;
                if (BlockHasSynPred(d.blockAST))
                    blocksWithSynPreds++;
                //if (g.decisionsWhoseDFAsUsesSynPreds.contains(d.dfa))
                //    dfaWithSynPred++;
                if (d.dfa.HasSynPred)
                    dfaWithSynPred++;
                //			NFAState decisionStartState = g.getDecisionNFAStartState(d.decision);
                //			int nalts = g.getNumberOfAltsForDecisionNFA(decisionStartState);
                //			for (int alt = 1; alt <= nalts; alt++) {
                //				int walkAlt =
                //					decisionStartState.translateDisplayAltToWalkAlt(alt);
                //				NFAState altLeftEdge = g.getNFAStateForAltOfDecision(decisionStartState, walkAlt);
                //			}
                //			int nalts = g.getNumberOfAltsForDecisionNFA(d.dfa.decisionNFAStartState);
                //			for (int a=1; a<nalts; a++) {
                //				NFAState altStart =
                //					g.getNFAStateForAltOfDecision(d.dfa.decisionNFAStartState, a);
                //			}
                if (!d.dfa.IsCyclic)
                {
                    if (d.dfa.IsClassicDFA)
                    {
                        int maxk = d.dfa.MaxLookaheadDepth;
                        //System.out.println("decision "+d.dfa.decisionNumber+" k="+maxk);
                        if (maxk == 1)
                            numLL1++;
                        depths.Add(maxk);
                    }
//.........这里部分代码省略.........
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:101,代码来源:GrammarReport.cs


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