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


C# ITokenStream.LT方法代码示例

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


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

示例1: DebugTokenStream

 public DebugTokenStream(ITokenStream input, IDebugEventListener dbg) {
     this.input = input;
     DebugListener = dbg;
     // force TokenStream to get at least first valid token
     // so we know if there are any hidden tokens first in the stream
     input.LT(1);
 }
开发者ID:EightPillars,项目名称:PathwayEditor,代码行数:7,代码来源:DebugTokenStream.cs

示例2: addOpenBrace

     public bool addOpenBrace(ITokenStream input, int braceCode)
     {
 //      if (input.LA(1)!=AS3_exLexer.LCURLY && input.LA(1)!=AS3_exLexer.RCURLY && (braceCode!=BraceAdd_Switch || (input.LA(1)!=AS3_exLexer.BREAK && input.LA(1)!=AS3_exLexer.CASE && input.LA(1)!=AS3_exLexer.DEFAULT)))
         {
             //if adding braces and the next statement is not a block statement
             addOpenBrace(input.LT(1), braceCode);
 //          return true;
         }       
         return true;
     }
开发者ID:JoeRobich,项目名称:flashdevelop,代码行数:10,代码来源:ASPrettyPrinter.cs

示例3: AdaptivePredict

        public virtual int AdaptivePredict(ITokenStream input, int decision,
								   ParserRuleContext outerContext)
        {
            if (debug || debug_list_atn_decisions)
            {
                Console.WriteLine("adaptivePredict decision " + decision +
                                       " exec LA(1)==" + GetLookaheadName(input) +
                                  " line " + input.LT(1).Line + ":" + input.LT(1).Column);
            }

            this.input = input;
            startIndex = input.Index;
            context = outerContext;
            DFA dfa = decisionToDFA[decision];
            thisDfa = dfa;

            int m = input.Mark();
            int index = startIndex;

            // Now we are certain to have a specific decision's DFA
            // But, do we still need an initial state?
            try
            {
                DFAState s0;
                if (dfa.IsPrecedenceDfa)
                {
                    // the start state for a precedence DFA depends on the current
                    // parser precedence, and is provided by a DFA method.
                    s0 = dfa.GetPrecedenceStartState(parser.Precedence);
                }
                else {
                    // the start state for a "regular" DFA is just s0
                    s0 = dfa.s0;
                }

                if (s0 == null)
                {
                    if (outerContext == null) outerContext = ParserRuleContext.EmptyContext;
                    if (debug || debug_list_atn_decisions)
                    {
                        Console.WriteLine("predictATN decision " + dfa.decision +
                                           " exec LA(1)==" + GetLookaheadName(input) +
                                           ", outerContext=" + outerContext.ToString(parser));
                    }

                    bool fullCtx = false;
                    ATNConfigSet s0_closure =
                        ComputeStartState(dfa.atnStartState,
                                          ParserRuleContext.EmptyContext,
                                          fullCtx);

                    if (dfa.IsPrecedenceDfa)
                    {
                        /* If this is a precedence DFA, we use applyPrecedenceFilter
                         * to convert the computed start state to a precedence start
                         * state. We then use DFA.setPrecedenceStartState to set the
                         * appropriate start state for the precedence level rather
                         * than simply setting DFA.s0.
                         */
                        dfa.s0.configSet = s0_closure; // not used for prediction but useful to know start configs anyway
                        s0_closure = ApplyPrecedenceFilter(s0_closure);
                        s0 = AddDFAState(dfa, new DFAState(s0_closure));
                        dfa.SetPrecedenceStartState(parser.Precedence, s0);
                    }
                    else {
                        s0 = AddDFAState(dfa, new DFAState(s0_closure));
                        dfa.s0 = s0;
                    }
                }

                int alt = ExecATN(dfa, s0, input, index, outerContext);
                if (debug)
                    Console.WriteLine("DFA after predictATN: " + dfa.ToString(parser.Vocabulary));
                return alt;
            }
            finally
            {
                mergeCache = null; // wack cache after each prediction
                thisDfa = null;
                input.Seek(index);
                input.Release(m);
            }
        }
开发者ID:antlr,项目名称:antlr4,代码行数:83,代码来源:ParserATNSimulator.cs

示例4: NoViableAlt

        protected NoViableAltException NoViableAlt(ITokenStream input,
												ParserRuleContext outerContext,
												ATNConfigSet configs,
												int startIndex)
        {
            return new NoViableAltException(parser, input,
                                                input.Get(startIndex),
                                                input.LT(1),
                                                configs, outerContext);
        }
开发者ID:antlr,项目名称:antlr4,代码行数:10,代码来源:ParserATNSimulator.cs

示例5: configs

        /** Performs ATN simulation to compute a predicted alternative based
         *  upon the remaining input, but also updates the DFA cache to avoid
         *  having to traverse the ATN again for the same input sequence.

         There are some key conditions we're looking for after computing a new
         set of ATN configs (proposed DFA state):
               * if the set is empty, there is no viable alternative for current symbol
               * does the state uniquely predict an alternative?
               * does the state have a conflict that would prevent us from
                 putting it on the work list?

         We also have some key operations to do:
               * add an edge from previous DFA state to potentially new DFA state, D,
                 upon current symbol but only if adding to work list, which means in all
                 cases except no viable alternative (and possibly non-greedy decisions?)
               * collecting predicates and adding semantic context to DFA accept states
               * adding rule context to context-sensitive DFA accept states
               * consuming an input symbol
               * reporting a conflict
               * reporting an ambiguity
               * reporting a context sensitivity
               * reporting insufficient predicates

         cover these cases:
            dead end
            single alt
            single alt + preds
            conflict
            conflict + preds
         */
        protected int ExecATN(DFA dfa, DFAState s0,
						   ITokenStream input, int startIndex,
						   ParserRuleContext outerContext)
        {
            if (debug || debug_list_atn_decisions)
            {
                Console.WriteLine("execATN decision " + dfa.decision +
                                   " exec LA(1)==" + GetLookaheadName(input) +
                                   " line " + input.LT(1).Line + ":" + input.LT(1).Column);
            }

            DFAState previousD = s0;

            if (debug) Console.WriteLine("s0 = " + s0);

            int t = input.LA(1);

            while (true)
            { // while more work
                DFAState D = GetExistingTargetState(previousD, t);
                if (D == null)
                {
                    D = ComputeTargetState(dfa, previousD, t);
                }

                if (D == ERROR)
                {
                    // if any configs in previous dipped into outer context, that
                    // means that input up to t actually finished entry rule
                    // at least for SLL decision. Full LL doesn't dip into outer
                    // so don't need special case.
                    // We will get an error no matter what so delay until after
                    // decision; better error message. Also, no reachable target
                    // ATN states in SLL implies LL will also get nowhere.
                    // If conflict in states that dip out, choose min since we
                    // will get error no matter what.
                    NoViableAltException e = NoViableAlt(input, outerContext, previousD.configSet, startIndex);
                    input.Seek(startIndex);
                    int alt = GetSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previousD.configSet, outerContext);
                    if (alt != ATN.INVALID_ALT_NUMBER)
                    {
                        return alt;
                    }
                    throw e;
                }

                if (D.requiresFullContext && mode != PredictionMode.SLL)
                {
                    // IF PREDS, MIGHT RESOLVE TO SINGLE ALT => SLL (or syntax error)
                    BitSet conflictingAlts = D.configSet.conflictingAlts;
                    if (D.predicates != null)
                    {
                        if (debug) Console.WriteLine("DFA state has preds in DFA sim LL failover");
                        int conflictIndex = input.Index;
                        if (conflictIndex != startIndex)
                        {
                            input.Seek(startIndex);
                        }

                        conflictingAlts = EvalSemanticContext(D.predicates, outerContext, true);
                        if (conflictingAlts.Cardinality() == 1)
                        {
                            if (debug) Console.WriteLine("Full LL avoided");
                            return conflictingAlts.NextSetBit(0);
                        }

                        if (conflictIndex != startIndex)
                        {
                            // restore the index so reporting the fallback to full
                            // context occurs with the index at the correct spot
//.........这里部分代码省略.........
开发者ID:antlr,项目名称:antlr4,代码行数:101,代码来源:ParserATNSimulator.cs


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