RemoveTransition() public method

public RemoveTransition ( int trans ) : void
trans int
return void
示例#1
0
        protected virtual void OptimizeExitBranches(DFAState d)
        {
            int sI = d.stateNumber;

            if (_visited.Contains(sI))
            {
                return; // already visited
            }
            _visited.Add(sI);
            int nAlts = d.dfa.NumberOfAlts;

            for (int i = 0; i < d.NumberOfTransitions; i++)
            {
                Transition edge       = (Transition)d.Transition(i);
                DFAState   edgeTarget = ((DFAState)edge.target);

                /*
                 * [email protected](d.stateNumber+"-"+
                 *                 edge.label.toString(d.dfa.nfa.grammar)+"->"+
                 *                 edgeTarget.stateNumber);
                 */
                // if target is an accept state and that alt is the exit alt
                if (edgeTarget.IsAcceptState &&
                    edgeTarget.GetUniquelyPredictedAlt() == nAlts)
                {
                    /*
                     * [email protected]("ignoring transition "+i+" to max alt "+
                     *  d.dfa.getNumberOfAlts());
                     */
                    d.RemoveTransition(i);
                    i--; // back up one so that i++ of loop iteration stays within bounds
                }
                OptimizeExitBranches(edgeTarget);
            }
        }
示例#2
0
        protected virtual void OptimizeEOTBranches(DFAState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state");
            }

            int sI = state.StateNumber;

            if (_visited.Contains(sI))
            {
                return; // already visited
            }
            _visited.Add(sI);
            for (int i = 0; i < state.NumberOfTransitions; i++)
            {
                Transition edge       = state.GetTransition(i);
                DFAState   edgeTarget = ((DFAState)edge.Target);

                /*
                 * [email protected](d.stateNumber+"-"+
                 *                 edge.label.toString(d.dfa.nfa.grammar)+"->"+
                 *                 edgeTarget.stateNumber);
                 */
                // if only one edge coming out, it is EOT, and target is accept prune
                if (PRUNE_TOKENS_RULE_SUPERFLUOUS_EOT_EDGES &&
                    edgeTarget.IsAcceptState &&
                    state.NumberOfTransitions == 1 &&
                    edge.Label.IsAtom &&
                    edge.Label.Atom == Label.EOT)
                {
                    //[email protected]("state "+d+" can be pruned");
                    // remove the superfluous EOT edge
                    state.RemoveTransition(i);
                    state.IsAcceptState = true; // make it an accept state
                    // force it to uniquely predict the originally predicted state
                    state.CachedUniquelyPredicatedAlt = edgeTarget.GetUniquelyPredictedAlt();
                    i--; // back up one so that i++ of loop iteration stays within bounds
                }
                OptimizeEOTBranches(edgeTarget);
            }
        }
示例#3
0
 protected virtual void OptimizeExitBranches( DFAState d )
 {
     int sI = d.stateNumber;
     if ( _visited.Contains( sI ) )
     {
         return; // already visited
     }
     _visited.Add( sI );
     int nAlts = d.dfa.NumberOfAlts;
     for ( int i = 0; i < d.NumberOfTransitions; i++ )
     {
         Transition edge = (Transition)d.Transition( i );
         DFAState edgeTarget = ( (DFAState)edge.target );
         /*
         [email protected](d.stateNumber+"-"+
                            edge.label.toString(d.dfa.nfa.grammar)+"->"+
                            edgeTarget.stateNumber);
         */
         // if target is an accept state and that alt is the exit alt
         if ( edgeTarget.IsAcceptState &&
             edgeTarget.GetUniquelyPredictedAlt() == nAlts )
         {
             /*
             [email protected]("ignoring transition "+i+" to max alt "+
                 d.dfa.getNumberOfAlts());
             */
             d.RemoveTransition( i );
             i--; // back up one so that i++ of loop iteration stays within bounds
         }
         OptimizeExitBranches( edgeTarget );
     }
 }
示例#4
0
 protected virtual void OptimizeEOTBranches( DFAState d )
 {
     int sI = d.stateNumber;
     if ( _visited.Contains( sI ) )
     {
         return; // already visited
     }
     _visited.Add( sI );
     for ( int i = 0; i < d.NumberOfTransitions; i++ )
     {
         Transition edge = (Transition)d.Transition( i );
         DFAState edgeTarget = ( (DFAState)edge.target );
         /*
         [email protected](d.stateNumber+"-"+
                            edge.label.toString(d.dfa.nfa.grammar)+"->"+
                            edgeTarget.stateNumber);
         */
         // if only one edge coming out, it is EOT, and target is accept prune
         if ( PRUNE_TOKENS_RULE_SUPERFLUOUS_EOT_EDGES &&
             edgeTarget.IsAcceptState &&
             d.NumberOfTransitions == 1 &&
             edge.label.IsAtom &&
             edge.label.Atom == Label.EOT )
         {
             //[email protected]("state "+d+" can be pruned");
             // remove the superfluous EOT edge
             d.RemoveTransition( i );
             d.IsAcceptState = true; // make it an accept state
             // force it to uniquely predict the originally predicted state
             d.cachedUniquelyPredicatedAlt =
                 edgeTarget.GetUniquelyPredictedAlt();
             i--; // back up one so that i++ of loop iteration stays within bounds
         }
         OptimizeEOTBranches( edgeTarget );
     }
 }