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


C# ATNState.Transition方法代码示例

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


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

示例1: GetDecisionLookahead

 public virtual IntervalSet[] GetDecisionLookahead(ATNState s)
 {
     //		System.out.println("LOOK("+s.stateNumber+")");
     if (s == null)
     {
         return null;
     }
     IntervalSet[] look = new IntervalSet[s.NumberOfTransitions + 1];
     for (int alt = 1; alt <= s.NumberOfTransitions; alt++)
     {
         look[alt] = new IntervalSet();
         HashSet<ATNConfig> lookBusy = new HashSet<ATNConfig>();
         bool seeThruPreds = false;
         // fail to get lookahead upon pred
         Look(s.Transition(alt - 1).target, PredictionContext.EmptyFull, look[alt], lookBusy
             , seeThruPreds, false);
         // Wipe out lookahead for this alternative if we found nothing
         // or we had a predicate when we !seeThruPreds
         if (look[alt].Size() == 0 || look[alt].Contains(HitPred))
         {
             look[alt] = null;
         }
     }
     return look;
 }
开发者ID:pabloescribano,项目名称:antlr4cs,代码行数:25,代码来源:LL1Analyzer.cs

示例2: Check

        /** From state s, look for any transition to a rule that is currently
         *  being traced.  When tracing r, visitedPerRuleCheck has r
         *  initially.  If you reach a rule stop state, return but notify the
         *  invoking rule that the called rule is nullable. This implies that
         *  invoking rule must look at follow transition for that invoking state.
         *
         *  The visitedStates tracks visited states within a single rule so
         *  we can avoid epsilon-loop-induced infinite recursion here.  Keep
         *  filling the cycles in listOfRecursiveCycles and also, as a
         *  side-effect, set leftRecursiveRules.
         */
        public virtual bool Check(Rule enclosingRule, ATNState s, ISet<ATNState> visitedStates)
        {
            if (s is RuleStopState)
                return true;
            if (visitedStates.Contains(s))
                return false;
            visitedStates.Add(s);

            //System.out.println("visit "+s);
            int n = s.NumberOfTransitions;
            bool stateReachesStopState = false;
            for (int i = 0; i < n; i++)
            {
                Transition t = s.Transition(i);
                if (t is RuleTransition)
                {
                    RuleTransition rt = (RuleTransition)t;
                    Rule r = g.GetRule(rt.ruleIndex);
                    if (rulesVisitedPerRuleCheck.Contains((RuleStartState)t.target))
                    {
                        AddRulesToCycle(enclosingRule, r);
                    }
                    else
                    {
                        // must visit if not already visited; mark target, pop when done
                        rulesVisitedPerRuleCheck.Add((RuleStartState)t.target);
                        // send new visitedStates set per rule invocation
                        bool nullable = Check(r, t.target, new HashSet<ATNState>());
                        // we're back from visiting that rule
                        rulesVisitedPerRuleCheck.Remove((RuleStartState)t.target);
                        if (nullable)
                        {
                            stateReachesStopState |= Check(enclosingRule, rt.followState, visitedStates);
                        }
                    }
                }
                else if (t.IsEpsilon)
                {
                    stateReachesStopState |= Check(enclosingRule, t.target, visitedStates);
                }
                // else ignore non-epsilon transitions
            }
            return stateReachesStopState;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:55,代码来源:LeftRecursionDetector.cs

示例3: VisitState

        protected internal virtual void VisitState(ATNState p)
        {
            int edge;
            if (p.NumberOfTransitions > 1)
            {
                ErrorHandler.Sync(this);
                edge = Interpreter.AdaptivePredict(_input, ((DecisionState)p).decision, _ctx);
            }
            else
            {
                edge = 1;
            }
            Transition transition = p.Transition(edge - 1);
            switch (transition.TransitionType)
            {
                case TransitionType.Epsilon:
                {
                    if (pushRecursionContextStates.Get(p.stateNumber) && !(transition.target is LoopEndState))
                    {
                        InterpreterRuleContext ctx = new InterpreterRuleContext(_parentContextStack.Peek().Item1, _parentContextStack.Peek().Item2, _ctx.RuleIndex);
                        PushNewRecursionContext(ctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.RuleIndex);
                    }
                    break;
                }

                case TransitionType.Atom:
                {
                    Match(((AtomTransition)transition).label);
                    break;
                }

                case TransitionType.Range:
                case TransitionType.Set:
                case TransitionType.NotSet:
                {
                    if (!transition.Matches(_input.La(1), TokenConstants.MinUserTokenType, 65535))
                    {
                        _errHandler.RecoverInline(this);
                    }
                    MatchWildcard();
                    break;
                }

                case TransitionType.Wildcard:
                {
                    MatchWildcard();
                    break;
                }

                case TransitionType.Rule:
                {
                    RuleStartState ruleStartState = (RuleStartState)transition.target;
                    int ruleIndex = ruleStartState.ruleIndex;
                    InterpreterRuleContext ctx_1 = new InterpreterRuleContext(_ctx, p.stateNumber, ruleIndex);
                    if (ruleStartState.isPrecedenceRule)
                    {
                        EnterRecursionRule(ctx_1, ruleStartState.stateNumber, ruleIndex, ((RuleTransition)transition).precedence);
                    }
                    else
                    {
                        EnterRule(ctx_1, transition.target.stateNumber, ruleIndex);
                    }
                    break;
                }

                case TransitionType.Predicate:
                {
                    PredicateTransition predicateTransition = (PredicateTransition)transition;
                    if (!Sempred(_ctx, predicateTransition.ruleIndex, predicateTransition.predIndex))
                    {
                        throw new FailedPredicateException(this);
                    }
                    break;
                }

                case TransitionType.Action:
                {
                    ActionTransition actionTransition = (ActionTransition)transition;
                    Action(_ctx, actionTransition.ruleIndex, actionTransition.actionIndex);
                    break;
                }

                case TransitionType.Precedence:
                {
                    if (!Precpred(_ctx, ((PrecedencePredicateTransition)transition).precedence))
                    {
                        throw new FailedPredicateException(this, string.Format("precpred(_ctx, {0})", ((PrecedencePredicateTransition)transition).precedence));
                    }
                    break;
                }

                default:
                {
                    throw new NotSupportedException("Unrecognized ATN transition type.");
                }
            }
            State = transition.target.stateNumber;
        }
开发者ID:nickdurcholz,项目名称:antlr4cs,代码行数:98,代码来源:ParserInterpreter.cs

示例4: ComputeStartState

        protected ATNConfigSet ComputeStartState(ATNState p,
											  RuleContext ctx,
											  bool fullCtx)
        {
            // always at least the implicit call to start rule
            PredictionContext initialContext = PredictionContext.FromRuleContext(atn, ctx);
            ATNConfigSet configs = new ATNConfigSet(fullCtx);

            for (int i = 0; i < p.NumberOfTransitions; i++)
            {
                ATNState target = p.Transition(i).target;
                ATNConfig c = new ATNConfig(target, i + 1, initialContext);
                HashSet<ATNConfig> closureBusy = new HashSet<ATNConfig>();
                Closure(c, configs, closureBusy, true, fullCtx, false);
            }

            return configs;
        }
开发者ID:antlr,项目名称:antlr4,代码行数:18,代码来源:ParserATNSimulator.cs

示例5: ComputeStartState

 protected internal virtual ATNConfigSet ComputeStartState(ICharStream input, ATNState
      p)
 {
     PredictionContext initialContext = PredictionContext.EmptyFull;
     ATNConfigSet configs = new OrderedATNConfigSet();
     for (int i = 0; i < p.NumberOfTransitions; i++)
     {
         ATNState target = p.Transition(i).target;
         ATNConfig c = ATNConfig.Create(target, i + 1, initialContext);
         Closure(input, c, configs, false);
     }
     return configs;
 }
开发者ID:hustsii,项目名称:antlr4cs,代码行数:13,代码来源:LexerATNSimulator.cs

示例6: Look


//.........这里部分代码省略.........
             if (ctx.IsEmpty && addEOF)
             {
                 look.Add(TokenConstants.Eof);
                 return;
             }
         }
         for (int i = 0; i < ctx.Size; i++)
         {
             if (ctx.GetReturnState(i) != PredictionContext.EmptyFullStateKey)
             {
                 ATNState returnState = atn.states[ctx.GetReturnState(i)];
                 //					System.out.println("popping back to "+retState);
                 for (int j = 0; j < ctx.Size; j++)
                 {
                     bool removed = calledRuleStack.Get(returnState.ruleIndex);
                     try
                     {
                         calledRuleStack.Clear(returnState.ruleIndex);
                         Look(returnState, stopState, ctx.GetParent(j), look, lookBusy, calledRuleStack, seeThruPreds
                             , addEOF);
                     }
                     finally
                     {
                         if (removed)
                         {
                             calledRuleStack.Set(returnState.ruleIndex);
                         }
                     }
                 }
                 return;
             }
         }
     }
     int n = s.NumberOfTransitions;
     for (int i_1 = 0; i_1 < n; i_1++)
     {
         Transition t = s.Transition(i_1);
         if (t.GetType() == typeof(RuleTransition))
         {
             if (calledRuleStack.Get(((RuleTransition)t).target.ruleIndex))
             {
                 continue;
             }
             PredictionContext newContext = ctx.GetChild(((RuleTransition)t).followState.stateNumber
                 );
             try
             {
                 calledRuleStack.Set(((RuleTransition)t).target.ruleIndex);
                 Look(t.target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds
                     , addEOF);
             }
             finally
             {
                 calledRuleStack.Clear(((RuleTransition)t).target.ruleIndex);
             }
         }
         else
         {
             if (t is AbstractPredicateTransition)
             {
                 if (seeThruPreds)
                 {
                     Look(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF
                         );
                 }
                 else
开发者ID:hustsii,项目名称:antlr4cs,代码行数:67,代码来源:LL1Analyzer.cs

示例7: VisitState

        protected internal virtual void VisitState(ATNState p)
        {
            int edge;
            if (p.NumberOfTransitions > 1)
            {
                ErrorHandler.Sync(this);
                edge = Interpreter.AdaptivePredict(TokenStream, ((DecisionState)p).decision, RuleContext);
            }
            else
            {
                edge = 1;
            }
            Transition transition = p.Transition(edge - 1);
            switch (transition.TransitionType)
            {
                case TransitionType.EPSILON:
                {
                    if (pushRecursionContextStates.Get(p.stateNumber) && !(transition.target is LoopEndState))
                    {
                        InterpreterRuleContext ctx = new InterpreterRuleContext(_parentContextStack.Peek().Item1, _parentContextStack.Peek().Item2, RuleContext.RuleIndex);
                        PushNewRecursionContext(ctx, _atn.ruleToStartState[p.ruleIndex].stateNumber, RuleContext.RuleIndex);
                    }
                    break;
                }

                case TransitionType.ATOM:
                {
                    Match(((AtomTransition)transition).token);
                    break;
                }

                case TransitionType.RANGE:
                case TransitionType.SET:
                case TransitionType.NOT_SET:
                {
                    if (!transition.Matches(TokenStream.LA(1), TokenConstants.MinUserTokenType, 65535))
                    {
                        ErrorHandler.RecoverInline(this);
                    }
                    MatchWildcard();
                    break;
                }

                case TransitionType.WILDCARD:
                {
                    MatchWildcard();
                    break;
                }

                case TransitionType.RULE:
                {
                    RuleStartState ruleStartState = (RuleStartState)transition.target;
                    int ruleIndex = ruleStartState.ruleIndex;
                    InterpreterRuleContext ctx_1 = new InterpreterRuleContext(RuleContext, p.stateNumber, ruleIndex);
                    if (ruleStartState.isPrecedenceRule)
                    {
                        EnterRecursionRule(ctx_1, ruleStartState.stateNumber, ruleIndex, ((RuleTransition)transition).precedence);
                    }
                    else
                    {
                        EnterRule(ctx_1, transition.target.stateNumber, ruleIndex);
                    }
                    break;
                }

                case TransitionType.PREDICATE:
                {
                    PredicateTransition predicateTransition = (PredicateTransition)transition;
                    if (!Sempred(RuleContext, predicateTransition.ruleIndex, predicateTransition.predIndex))
                    {
                        throw new FailedPredicateException(this);
                    }
                    break;
                }

                case TransitionType.ACTION:
                {
                    ActionTransition actionTransition = (ActionTransition)transition;
                    Action(RuleContext, actionTransition.ruleIndex, actionTransition.actionIndex);
                    break;
                }

                case TransitionType.PRECEDENCE:
                {
                    if (!Precpred(RuleContext, ((PrecedencePredicateTransition)transition).precedence))
                    {
                        throw new FailedPredicateException(this, string.Format("precpred(_ctx, {0})", ((PrecedencePredicateTransition)transition).precedence));
                    }
                    break;
                }

                default:
                {
                    throw new NotSupportedException("Unrecognized ATN transition type.");
                }
            }
            State = transition.target.stateNumber;
        }
开发者ID:antlr,项目名称:antlr4,代码行数:98,代码来源:ParserInterpreter.cs

示例8: VisitState

        protected internal virtual void VisitState(ATNState p)
        {
            int predictedAlt = 1;
            if (p.NumberOfTransitions > 1)
            {
                predictedAlt = VisitDecisionState((DecisionState)p);
            }
            Transition transition = p.Transition(predictedAlt - 1);
            switch (transition.TransitionType)
            {
                case TransitionType.Epsilon:
                {
                    if (pushRecursionContextStates.Get(p.stateNumber) && !(transition.target is LoopEndState))
                    {
                        // We are at the start of a left recursive rule's (...)* loop
                        // and we're not taking the exit branch of loop.
                        InterpreterRuleContext localctx = CreateInterpreterRuleContext(_parentContextStack.Peek().Item1, _parentContextStack.Peek().Item2, _ctx.RuleIndex);
                        PushNewRecursionContext(localctx, atn.ruleToStartState[p.ruleIndex].stateNumber, _ctx.RuleIndex);
                    }
                    break;
                }

                case TransitionType.Atom:
                {
                    Match(((AtomTransition)transition).label);
                    break;
                }

                case TransitionType.Range:
                case TransitionType.Set:
                case TransitionType.NotSet:
                {
                    if (!transition.Matches(_input.La(1), TokenConstants.MinUserTokenType, 65535))
                    {
                        RecoverInline();
                    }
                    MatchWildcard();
                    break;
                }

                case TransitionType.Wildcard:
                {
                    MatchWildcard();
                    break;
                }

                case TransitionType.Rule:
                {
                    RuleStartState ruleStartState = (RuleStartState)transition.target;
                    int ruleIndex = ruleStartState.ruleIndex;
                    InterpreterRuleContext newctx = CreateInterpreterRuleContext(_ctx, p.stateNumber, ruleIndex);
                    if (ruleStartState.isPrecedenceRule)
                    {
                        EnterRecursionRule(newctx, ruleStartState.stateNumber, ruleIndex, ((RuleTransition)transition).precedence);
                    }
                    else
                    {
                        EnterRule(newctx, transition.target.stateNumber, ruleIndex);
                    }
                    break;
                }

                case TransitionType.Predicate:
                {
                    PredicateTransition predicateTransition = (PredicateTransition)transition;
                    if (!Sempred(_ctx, predicateTransition.ruleIndex, predicateTransition.predIndex))
                    {
                        throw new FailedPredicateException(this);
                    }
                    break;
                }

                case TransitionType.Action:
                {
                    ActionTransition actionTransition = (ActionTransition)transition;
                    Action(_ctx, actionTransition.ruleIndex, actionTransition.actionIndex);
                    break;
                }

                case TransitionType.Precedence:
                {
                    if (!Precpred(_ctx, ((PrecedencePredicateTransition)transition).precedence))
                    {
                        throw new FailedPredicateException(this, string.Format("precpred(_ctx, {0})", ((PrecedencePredicateTransition)transition).precedence));
                    }
                    break;
                }

                default:
                {
                    throw new NotSupportedException("Unrecognized ATN transition type.");
                }
            }
            State = transition.target.stateNumber;
        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:95,代码来源:ParserInterpreter.cs

示例9: ComputeStartState

        protected ATNConfigSet ComputeStartState(ICharStream input,
												 ATNState p)
        {
            PredictionContext initialContext = PredictionContext.EMPTY;
            ATNConfigSet configs = new OrderedATNConfigSet();
            for (int i = 0; i < p.NumberOfTransitions; i++)
            {
                ATNState target = p.Transition(i).target;
                LexerATNConfig c = new LexerATNConfig(target, i + 1, initialContext);
                Closure(input, c, configs, false, false, false);
            }
            return configs;
        }
开发者ID:antlr,项目名称:antlr4,代码行数:13,代码来源:LexerATNSimulator.cs

示例10: Look


//.........这里部分代码省略.........
         }
     }
     if (s is RuleStopState)
     {
         if (ctx == null)
         {
             look.Add(TokenConstants.EPSILON);
             return;
         }
         else if (ctx.IsEmpty && addEOF)
         {
             look.Add(TokenConstants.EOF);
             return;
         }
         if (ctx != PredictionContext.EMPTY)
         {
             for (int i = 0; i < ctx.Size; i++)
             {
                 ATNState returnState = atn.states[ctx.GetReturnState(i)];
                 bool removed = calledRuleStack.Get(returnState.ruleIndex);
                 try
                 {
                     calledRuleStack.Clear(returnState.ruleIndex);
                     Look(returnState, stopState, ctx.GetParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
                 }
                 finally
                 {
                     if (removed)
                     {
                         calledRuleStack.Set(returnState.ruleIndex);
                     }
                 }
             }
             return;
         }
     }
     int n = s.NumberOfTransitions;
     for (int i_1 = 0; i_1 < n; i_1++)
     {
         Transition t = s.Transition(i_1);
         if (t is RuleTransition)
         {
             RuleTransition ruleTransition = (RuleTransition)t;
             if (calledRuleStack.Get(ruleTransition.ruleIndex))
             {
                 continue;
             }
             PredictionContext newContext = SingletonPredictionContext.Create(ctx, ruleTransition.followState.stateNumber);
             try
             {
                 calledRuleStack.Set(ruleTransition.target.ruleIndex);
                 Look(t.target, stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
             }
             finally
             {
                 calledRuleStack.Clear(ruleTransition.target.ruleIndex);
             }
         }
         else
         {
             if (t is AbstractPredicateTransition)
             {
                 if (seeThruPreds)
                 {
                     Look(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
                 }
                 else
                 {
                     look.Add(HitPred);
                 }
             }
             else
             {
                 if (t.IsEpsilon)
                 {
                     Look(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
                 }
                 else
                 {
                     if (t is WildcardTransition)
                     {
                         look.AddAll(IntervalSet.Of(TokenConstants.MinUserTokenType, atn.maxTokenType));
                     }
                     else
                     {
                         IntervalSet set = t.Label;
                         if (set != null)
                         {
                             if (t is NotSetTransition)
                             {
                                 set = set.Complement(IntervalSet.Of(TokenConstants.MinUserTokenType, atn.maxTokenType));
                             }
                             look.AddAll(set);
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:antlr,项目名称:antlr4,代码行数:101,代码来源:LL1Analyzer.cs


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