예제 #1
0
 public virtual int DefineDecisionState(DecisionState s)
 {
     decisionToState.Add(s);
     s.decision    = decisionToState.Count - 1;
     decisionToDFA = Arrays.CopyOf(decisionToDFA, decisionToState.Count);
     decisionToDFA[decisionToDFA.Length - 1] = new DFA(s, s.decision);
     return(s.decision);
 }
예제 #2
0
        protected internal virtual void ReadDecisions(ATN atn)
        {
            //
            // DECISIONS
            //
            int ndecisions = ReadInt();

            for (int i_11 = 0; i_11 < ndecisions; i_11++)
            {
                int           s        = ReadInt();
                DecisionState decState = (DecisionState)atn.states[s];
                atn.decisionToState.Add(decState);
                decState.decision = i_11;
            }
            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);
            }
        }
예제 #3
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);
         }
     }
 }