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


C# ATN.DefineDecisionState方法代码示例

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


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

示例1: GenerateRuleBypassTransitions

 protected internal virtual void GenerateRuleBypassTransitions(ATN atn)
 {
     atn.ruleToTokenType = new int[atn.ruleToStartState.Length];
     for (int i_10 = 0; i_10 < atn.ruleToStartState.Length; i_10++)
     {
         atn.ruleToTokenType[i_10] = atn.maxTokenType + i_10 + 1;
     }
     for (int i_13 = 0; i_13 < atn.ruleToStartState.Length; i_13++)
     {
         BasicBlockStartState bypassStart = new BasicBlockStartState();
         bypassStart.ruleIndex = i_13;
         atn.AddState(bypassStart);
         BlockEndState bypassStop = new BlockEndState();
         bypassStop.ruleIndex = i_13;
         atn.AddState(bypassStop);
         bypassStart.endState = bypassStop;
         atn.DefineDecisionState(bypassStart);
         bypassStop.startState = bypassStart;
         ATNState endState;
         Transition excludeTransition = null;
         if (atn.ruleToStartState[i_13].isPrecedenceRule)
         {
             // wrap from the beginning of the rule to the StarLoopEntryState
             endState = null;
             foreach (ATNState state_3 in atn.states)
             {
                 if (state_3.ruleIndex != i_13)
                 {
                     continue;
                 }
                 if (!(state_3 is StarLoopEntryState))
                 {
                     continue;
                 }
                 ATNState maybeLoopEndState = state_3.Transition(state_3.NumberOfTransitions - 1).target;
                 if (!(maybeLoopEndState is LoopEndState))
                 {
                     continue;
                 }
                 if (maybeLoopEndState.epsilonOnlyTransitions && maybeLoopEndState.Transition(0).target is RuleStopState)
                 {
                     endState = state_3;
                     break;
                 }
             }
             if (endState == null)
             {
                 throw new NotSupportedException("Couldn't identify final state of the precedence rule prefix section.");
             }
             excludeTransition = ((StarLoopEntryState)endState).loopBackState.Transition(0);
         }
         else
         {
             endState = atn.ruleToStopState[i_13];
         }
         // all non-excluded transitions that currently target end state need to target blockEnd instead
         foreach (ATNState state_4 in atn.states)
         {
             foreach (Transition transition in state_4.transitions)
             {
                 if (transition == excludeTransition)
                 {
                     continue;
                 }
                 if (transition.target == endState)
                 {
                     transition.target = bypassStop;
                 }
             }
         }
         // all transitions leaving the rule start state need to leave blockStart instead
         while (atn.ruleToStartState[i_13].NumberOfTransitions > 0)
         {
             Transition transition = atn.ruleToStartState[i_13].Transition(atn.ruleToStartState[i_13].NumberOfTransitions - 1);
             atn.ruleToStartState[i_13].RemoveTransition(atn.ruleToStartState[i_13].NumberOfTransitions - 1);
             bypassStart.AddTransition(transition);
         }
         // link the new states
         atn.ruleToStartState[i_13].AddTransition(new EpsilonTransition(bypassStart));
         bypassStop.AddTransition(new EpsilonTransition(endState));
         ATNState matchState = new BasicState();
         atn.AddState(matchState);
         matchState.AddTransition(new AtomTransition(bypassStop, atn.ruleToTokenType[i_13]));
         bypassStart.AddTransition(new EpsilonTransition(matchState));
     }
     if (deserializationOptions.VerifyAtn)
     {
         // reverify after modification
         VerifyATN(atn);
     }
 }
开发者ID:antlr,项目名称:antlr4,代码行数:91,代码来源:ATNDeserializer.cs

示例2: Deserialize


//.........这里部分代码省略.........
                            state_3.SetTransition(i_10, new ActionTransition(transition.target, ruleIndex, legacyLexerActions.Count, false));
                            legacyLexerActions.Add(lexerAction);
                        }
                    }
                    atn.lexerActions = legacyLexerActions.ToArray();
                }
            }
            MarkPrecedenceDecisions(atn);
            atn.decisionToDFA = new DFA[ndecisions];
            for (int i_12 = 0; i_12 < ndecisions; i_12++)
            {
                atn.decisionToDFA[i_12] = new DFA(atn.decisionToState[i_12], i_12);
            }
            if (deserializationOptions.VerifyAtn)
            {
                VerifyATN(atn);
            }
            if (deserializationOptions.GenerateRuleBypassTransitions && atn.grammarType == ATNType.Parser)
            {
                atn.ruleToTokenType = new int[atn.ruleToStartState.Length];
                for (int i_10 = 0; i_10 < atn.ruleToStartState.Length; i_10++)
                {
                    atn.ruleToTokenType[i_10] = atn.maxTokenType + i_10 + 1;
                }
                for (int i_13 = 0; i_13 < atn.ruleToStartState.Length; i_13++)
                {
                    BasicBlockStartState bypassStart = new BasicBlockStartState();
                    bypassStart.ruleIndex = i_13;
                    atn.AddState(bypassStart);
                    BlockEndState bypassStop = new BlockEndState();
                    bypassStop.ruleIndex = i_13;
                    atn.AddState(bypassStop);
                    bypassStart.endState = bypassStop;
                    atn.DefineDecisionState(bypassStart);
                    bypassStop.startState = bypassStart;
                    ATNState endState;
                    Transition excludeTransition = null;
                    if (atn.ruleToStartState[i_13].isPrecedenceRule)
                    {
                        // wrap from the beginning of the rule to the StarLoopEntryState
                        endState = null;
                        foreach (ATNState state_3 in atn.states)
                        {
                            if (state_3.ruleIndex != i_13)
                            {
                                continue;
                            }
                            if (!(state_3 is StarLoopEntryState))
                            {
                                continue;
                            }
                            ATNState maybeLoopEndState = state_3.Transition(state_3.NumberOfTransitions - 1).target;
                            if (!(maybeLoopEndState is LoopEndState))
                            {
                                continue;
                            }
                            if (maybeLoopEndState.epsilonOnlyTransitions && maybeLoopEndState.Transition(0).target is RuleStopState)
                            {
                                endState = state_3;
                                break;
                            }
                        }
                        if (endState == null)
                        {
                            throw new NotSupportedException("Couldn't identify final state of the precedence rule prefix section.");
                        }
开发者ID:sharwell,项目名称:antlr4cs,代码行数:67,代码来源:ATNDeserializer.cs


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