Logo Search packages:      
Sourcecode: lttoolbox version File versions  Download package

int Transducer::insertSingleTransduction ( int const   tag,
int const   source 
)

Insertion of a single transduction, creating a new target state if needed

Parameters:
tag the tag of the transduction being inserted
source the source state of the new transduction
Returns:
the target state

Definition at line 70 of file Transducer.C.

References newState(), and transitions.

Referenced by Compiler::matchTransduction().

{
  if(transitions.find(source) != transitions.end())
  {
    if(transitions[source].count(tag) == 1)
    {
      pair<multimap<int,int>::iterator, multimap<int,int>::iterator > range;
      range = transitions[source].equal_range(tag);
      return range.first->second;
    }
    else if(transitions[source].count(tag) == 0)
    {
      // new state
      int state = newState();
      transitions[source].insert(pair<int, int>(tag, state));
      return state;
    }
    else if(transitions[source].count(tag) == 2)
    {
      // there's a local cycle, must be ignored and treated like in '1'
      pair<multimap<int,int>::iterator, multimap<int,int>::iterator> range;
      range = transitions[source].equal_range(tag);
      for(; range.first != range.second; range.first++)
      {
        if(range.first->second != source)
        {
          return range.first->second;
        }
      }
      return -1; 
    } 
    else
    {
      return -1;
    }
  }
  else
  {
    return -1;
  }
}


Generated by  Doxygen 1.6.0   Back to index