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


C# Grammar.GetOption方法代码示例

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


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

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

示例2: GenerateRecognizer

        /** Create NFA, DFA and generate code for grammar.
         *  Create NFA for any delegates first.  Once all NFA are created,
         *  it's ok to create DFA, which must check for left-recursion.  That check
         *  is done by walking the full NFA, which therefore must be complete.
         *  After all NFA, comes DFA conversion for root grammar then code gen for
         *  root grammar.  DFA and code gen for delegates comes next.
         */
        protected virtual void GenerateRecognizer( Grammar grammar )
        {
            string language = (string)grammar.GetOption( "language" );
            if ( language != null )
            {
                CodeGenerator generator = new CodeGenerator( this, grammar, language );
                grammar.CodeGenerator = generator;
                generator.Debug = Debug;
                generator.Profile = Profile;
                generator.Trace = Trace;

                // generate NFA early in case of crash later (for debugging)
                if ( Generate_NFA_dot )
                {
                    GenerateNFAs( grammar );
                }

                // GENERATE CODE
                generator.GenRecognizer();

                if ( Generate_DFA_dot )
                {
                    GenerateDFAs( grammar );
                }

                IList<Grammar> delegates = grammar.GetDirectDelegates();
                for ( int i = 0; delegates != null && i < delegates.Count; i++ )
                {
                    Grammar @delegate = (Grammar)delegates[i];
                    if ( @delegate != grammar )
                    {
                        // already processing this one
                        GenerateRecognizer( @delegate );
                    }
                }
            }
        }
开发者ID:antlr,项目名称:antlrcs,代码行数:44,代码来源:AntlrTool.cs

示例3: BuildDependencyGenerator

 public BuildDependencyGenerator( Tool tool, string grammarFileName )
 {
     this.tool = tool;
     this.grammarFileName = grammarFileName;
     grammar = tool.GetRootGrammar( grammarFileName );
     string language = (string)grammar.GetOption( "language" );
     generator = new CodeGenerator( tool, grammar, language );
     generator.LoadTemplates( language );
 }
开发者ID:bszafko,项目名称:antlrcs,代码行数:9,代码来源:BuildDependencyGenerator.cs

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