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


C# ITokenStream.Consume方法代码示例

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


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

示例1: TokenStreamVisualizerForm

        public TokenStreamVisualizerForm( ITokenStream tokenStream )
        {
            if (tokenStream == null)
                throw new ArgumentNullException("tokenStream");

            InitializeComponent();

            List<IToken> tokens = new List<IToken>();

            int marker = tokenStream.Mark();
            int currentPosition = tokenStream.Index;
            try
            {
                tokenStream.Seek(0);
                while (tokenStream.LA(1) != CharStreamConstants.EndOfFile)
                    tokenStream.Consume();

                for (int i = 0; i < tokenStream.Count; i++)
                    tokens.Add(tokenStream.Get(i));
            }
            finally
            {
                tokenStream.Rewind(marker);
            }

            this._tokenStream = tokenStream;
            this._tokens = tokens.ToArray();

            if (tokenStream.TokenSource != null)
                this._tokenNames = tokenStream.TokenSource.TokenNames;

            this._tokenNames = this._tokenNames ?? new string[0];

            UpdateTokenTypes();
            UpdateHighlighting();

            listBox1.BackColor = Color.Wheat;
        }
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:38,代码来源:TokenStreamVisualizerForm.cs

示例2: ExecATNWithFullContext

        // comes back with reach.UniqueAlt set to a valid alt
        protected int ExecATNWithFullContext(DFA dfa,
											 DFAState D, // how far we got in SLL DFA before failing over
											 ATNConfigSet s0,
											 ITokenStream input, int startIndex,
											 ParserRuleContext outerContext)
        {
            if (debug || debug_list_atn_decisions)
            {
                Console.WriteLine("execATNWithFullContext " + s0);
            }
            bool fullCtx = true;
            bool foundExactAmbig = false;
            ATNConfigSet reach = null;
            ATNConfigSet previous = s0;
            input.Seek(startIndex);
            int t = input.LA(1);
            int predictedAlt;
            while (true)
            { // while more work
              //			Console.WriteLine("LL REACH "+GetLookaheadName(input)+
              //							   " from configs.size="+previous.size()+
              //							   " line "+input.LT(1)Line+":"+input.LT(1).Column);
                reach = ComputeReachSet(previous, t, fullCtx);
                if (reach == null)
                {
                    // if any configs in previous dipped into outer context, that
                    // means that input up to t actually finished entry rule
                    // at least for LL 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, previous, startIndex);
                    input.Seek(startIndex);
                    int alt = GetSynValidOrSemInvalidAltThatFinishedDecisionEntryRule(previous, outerContext);
                    if (alt != ATN.INVALID_ALT_NUMBER)
                    {
                        return alt;
                    }
                    throw e;
                }

                ICollection<BitSet> altSubSets = PredictionMode.GetConflictingAltSubsets(reach.configs);
                if (debug)
                {
                    Console.WriteLine("LL altSubSets=" + altSubSets +
                                       ", predict=" + PredictionMode.GetUniqueAlt(altSubSets) +
                                       ", ResolvesToJustOneViableAlt=" +
                                           PredictionMode.ResolvesToJustOneViableAlt(altSubSets));
                }

                //			Console.WriteLine("altSubSets: "+altSubSets);
                //			System.err.println("reach="+reach+", "+reach.conflictingAlts);
                reach.uniqueAlt = GetUniqueAlt(reach);
                // unique prediction?
                if (reach.uniqueAlt != ATN.INVALID_ALT_NUMBER)
                {
                    predictedAlt = reach.uniqueAlt;
                    break;
                }
                if (mode != PredictionMode.LL_EXACT_AMBIG_DETECTION)
                {
                    predictedAlt = PredictionMode.ResolvesToJustOneViableAlt(altSubSets);
                    if (predictedAlt != ATN.INVALID_ALT_NUMBER)
                    {
                        break;
                    }
                }
                else {
                    // In exact ambiguity mode, we never try to terminate early.
                    // Just keeps scarfing until we know what the conflict is
                    if (PredictionMode.AllSubsetsConflict(altSubSets) &&
                         PredictionMode.AllSubsetsEqual(altSubSets))
                    {
                        foundExactAmbig = true;
                        predictedAlt = PredictionMode.GetSingleViableAlt(altSubSets);
                        break;
                    }
                    // else there are multiple non-conflicting subsets or
                    // we're not sure what the ambiguity is yet.
                    // So, keep going.
                }

                previous = reach;
                if (t != IntStreamConstants.EOF)
                {
                    input.Consume();
                    t = input.LA(1);
                }
            }

            // If the configuration set uniquely predicts an alternative,
            // without conflict, then we know that it's a full LL decision
            // not SLL.
            if (reach.uniqueAlt != ATN.INVALID_ALT_NUMBER)
            {
                ReportContextSensitivity(dfa, predictedAlt, reach, startIndex, input.Index);
//.........这里部分代码省略.........
开发者ID:antlr,项目名称:antlr4,代码行数:101,代码来源:ParserATNSimulator.cs

示例3: configs


//.........这里部分代码省略.........
                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
                            input.Seek(conflictIndex);
                        }
                    }

                    if (dfa_debug) Console.WriteLine("ctx sensitive state " + outerContext + " in " + D);
                    bool fullCtx = true;
                    ATNConfigSet s0_closure =
                        ComputeStartState(dfa.atnStartState, outerContext, fullCtx);
                    ReportAttemptingFullContext(dfa, conflictingAlts, D.configSet, startIndex, input.Index);
                    int alt = ExecATNWithFullContext(dfa, D, s0_closure,
                                                     input, startIndex,
                                                     outerContext);
                    return alt;
                }

                if (D.isAcceptState)
                {
                    if (D.predicates == null)
                    {
                        return D.prediction;
                    }

                    int stopIndex = input.Index;
                    input.Seek(startIndex);
                    BitSet alts = EvalSemanticContext(D.predicates, outerContext, true);
                    switch (alts.Cardinality())
                    {
                        case 0:
                            throw NoViableAlt(input, outerContext, D.configSet, startIndex);

                        case 1:
                            return alts.NextSetBit(0);

                        default:
                            // report ambiguity after predicate evaluation to make sure the correct
                            // set of ambig alts is reported.
                            ReportAmbiguity(dfa, D, startIndex, stopIndex, false, alts, D.configSet);
                            return alts.NextSetBit(0);
                    }
                }

                previousD = D;

                if (t != IntStreamConstants.EOF)
                {
                    input.Consume();
                    t = input.LA(1);
                }
            }
        }
开发者ID:antlr,项目名称:antlr4,代码行数:101,代码来源:ParserATNSimulator.cs


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