Inheritance: DecisionState
Exemple #1
0
        protected internal virtual ATNState StateFactory(StateType type, int ruleIndex)
        {
            ATNState s;

            switch (type)
            {
            case StateType.InvalidType:
            {
                return(null);
            }

            case StateType.Basic:
            {
                s = new BasicState();
                break;
            }

            case StateType.RuleStart:
            {
                s = new RuleStartState();
                break;
            }

            case StateType.BlockStart:
            {
                s = new BasicBlockStartState();
                break;
            }

            case StateType.PlusBlockStart:
            {
                s = new PlusBlockStartState();
                break;
            }

            case StateType.StarBlockStart:
            {
                s = new StarBlockStartState();
                break;
            }

            case StateType.TokenStart:
            {
                s = new TokensStartState();
                break;
            }

            case StateType.RuleStop:
            {
                s = new RuleStopState();
                break;
            }

            case StateType.BlockEnd:
            {
                s = new BlockEndState();
                break;
            }

            case StateType.StarLoopBack:
            {
                s = new StarLoopbackState();
                break;
            }

            case StateType.StarLoopEntry:
            {
                s = new StarLoopEntryState();
                break;
            }

            case StateType.PlusLoopBack:
            {
                s = new PlusLoopbackState();
                break;
            }

            case StateType.LoopEnd:
            {
                s = new LoopEndState();
                break;
            }

            default:
            {
                string message = string.Format(CultureInfo.CurrentCulture, "The specified state type {0} is not valid.", type);
                throw new ArgumentException(message);
            }
            }
            s.ruleIndex = ruleIndex;
            return(s);
        }
Exemple #2
0
 protected internal virtual void VerifyATN(ATN atn)
 {
     // verify assumptions
     foreach (ATNState state in atn.states)
     {
         if (state == null)
         {
             continue;
         }
         CheckCondition(state.OnlyHasEpsilonTransitions || state.NumberOfTransitions <= 1);
         if (state is PlusBlockStartState)
         {
             CheckCondition(((PlusBlockStartState)state).loopBackState != null);
         }
         if (state is StarLoopEntryState)
         {
             StarLoopEntryState starLoopEntryState = (StarLoopEntryState)state;
             CheckCondition(starLoopEntryState.loopBackState != null);
             CheckCondition(starLoopEntryState.NumberOfTransitions == 2);
             if (starLoopEntryState.Transition(0).target is StarBlockStartState)
             {
                 CheckCondition(starLoopEntryState.Transition(1).target is LoopEndState);
                 CheckCondition(!starLoopEntryState.nonGreedy);
             }
             else
             {
                 if (starLoopEntryState.Transition(0).target is LoopEndState)
                 {
                     CheckCondition(starLoopEntryState.Transition(1).target is StarBlockStartState);
                     CheckCondition(starLoopEntryState.nonGreedy);
                 }
                 else
                 {
                     throw new InvalidOperationException();
                 }
             }
         }
         if (state is StarLoopbackState)
         {
             CheckCondition(state.NumberOfTransitions == 1);
             CheckCondition(state.Transition(0).target is StarLoopEntryState);
         }
         if (state is LoopEndState)
         {
             CheckCondition(((LoopEndState)state).loopBackState != null);
         }
         if (state is RuleStartState)
         {
             CheckCondition(((RuleStartState)state).stopState != null);
         }
         if (state is BlockStartState)
         {
             CheckCondition(((BlockStartState)state).endState != null);
         }
         if (state is BlockEndState)
         {
             CheckCondition(((BlockEndState)state).startState != null);
         }
         if (state is DecisionState)
         {
             DecisionState decisionState = (DecisionState)state;
             CheckCondition(decisionState.NumberOfTransitions <= 1 || decisionState.decision >= 0);
         }
         else
         {
             CheckCondition(state.NumberOfTransitions <= 1 || state is RuleStopState);
         }
     }
 }
Exemple #3
0
        protected internal virtual ATNState StateFactory(StateType type, int ruleIndex)
        {
            ATNState s;
            switch (type)
            {
                case StateType.InvalidType:
                {
                    return null;
                }

                case StateType.Basic:
                {
                    s = new BasicState();
                    break;
                }

                case StateType.RuleStart:
                {
                    s = new RuleStartState();
                    break;
                }

                case StateType.BlockStart:
                {
                    s = new BasicBlockStartState();
                    break;
                }

                case StateType.PlusBlockStart:
                {
                    s = new PlusBlockStartState();
                    break;
                }

                case StateType.StarBlockStart:
                {
                    s = new StarBlockStartState();
                    break;
                }

                case StateType.TokenStart:
                {
                    s = new TokensStartState();
                    break;
                }

                case StateType.RuleStop:
                {
                    s = new RuleStopState();
                    break;
                }

                case StateType.BlockEnd:
                {
                    s = new BlockEndState();
                    break;
                }

                case StateType.StarLoopBack:
                {
                    s = new StarLoopbackState();
                    break;
                }

                case StateType.StarLoopEntry:
                {
                    s = new StarLoopEntryState();
                    break;
                }

                case StateType.PlusLoopBack:
                {
                    s = new PlusLoopbackState();
                    break;
                }

                case StateType.LoopEnd:
                {
                    s = new LoopEndState();
                    break;
                }

                default:
                {
                    string message = string.Format(CultureInfo.CurrentCulture, "The specified state type {0} is not valid.", type);
                    throw new ArgumentException(message);
                }
            }
            s.ruleIndex = ruleIndex;
            return s;
        }