本文整理汇总了C++中NFA::addInput方法的典型用法代码示例。如果您正苦于以下问题:C++ NFA::addInput方法的具体用法?C++ NFA::addInput怎么用?C++ NFA::addInput使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NFA
的用法示例。
在下文中一共展示了NFA::addInput方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: diff
automata::NFA<nfa_state_t, token_t>* RuleState::createNFA()
{
using automata::NFA;
/// maps paths uniquely to an nfa_state
std::map<path_t, nfa_state_t> nfa_states;
nfa_states.clear();
path_t prefix;
// START and EMPTY are both: tokens and nfa_states
prefix.push_back(START);
nfa_states[prefix] = START;
prefix[0] = EMPTY;
nfa_states[prefix] = EMPTY;
std::set<nfa_state_t> deflt;
deflt.insert(EMPTY);
NFA<nfa_state_t, token_t> *nfa = new NFA<nfa_state_t, token_t>(START, deflt);
nfa->addState(EMPTY);
nfa->addInput(ANY);
nfa->addTransition(EMPTY, ANY, EMPTY);
for (unsigned int i = 0; i < rules.size(); ++i)
{
const std::string currPattern(fromXMLString(rules[i].first));
const unsigned int len = currPattern.length();
int pos;
nfa_state_t lastState;
// determine if this is a start pattern
prefix.resize(1);
if (currPattern[0] == '/') {
prefix[0] = START;
pos = 1;
lastState = START;
}
else {
prefix[0] = EMPTY;
pos = 0;
lastState = EMPTY;
}
// std::cerr << "looking at pattern: " << currPattern << "\n";
// for all prefixes
do {
std::string::size_type pos2 = currPattern.find('/', pos);
if (pos2 == std::string::npos)
pos2 = len;
std::string diff(currPattern.substr(pos, pos2-pos));
token_t tok = createToken(fromSTLString(diff));
// std::cerr << pos << "-" << pos2 << "\t: " << diff << " = " << tok << "\n";
// create loop if REPEAT token
if (tok == REPEAT) {
nfa->addTransition(lastState, ANY, lastState); //FIXME: that's wrong, need to create repeating state
// std::cerr << "T " << lastState << "--*-->" << lastState << "\n";
pos = pos2 + 1;
continue;
}
prefix.push_back(tok);
// create new state if necessary
nfa_state_t nstate;
if (nfa_states.find(prefix) != nfa_states.end()) {
nstate = nfa_states[prefix];
}
else {
nstate = nfa_states.size();
nfa->addState(nstate);
nfa_states[prefix] = nstate;
}
// add transition
nfa->addInput(tok);
nfa->addTransition(lastState, tok, nstate);
// std::cerr << "T " << lastState << "--(" << tok << ")-->" << nstate << "\n";
lastState = nstate;
pos = pos2 + 1;
} while(pos < signed(len));
accepting.push_back(lastState);
// std::cerr << "accepted in " << lastState << "\n";
// copy all transition from EMPTY to all other states
const NFA<nfa_state_t, token_t>::Transitions& transFromEmpty(nfa->transitions(EMPTY));
std::set<nfa_state_t>::const_iterator it, st;
NFA<nfa_state_t, token_t>::Transitions::const_iterator tr;
for (it = nfa->states().begin(); it != nfa->states().end(); ++it) {
if (*it == EMPTY)
continue;
for (tr = transFromEmpty.begin(); tr != transFromEmpty.end(); ++tr)
for (st = tr->second.begin(); st != tr->second.end(); ++st)
nfa->addTransition(*it, tr->first, *st);
}
// ANY transitions
const std::set<token_t>& inputs(nfa->inputs());
//.........这里部分代码省略.........