23 StateSet::Iterator its;
37 std::string annotation = word +
"-";
43 StackSymbolSet::Iterator it;
57 std::vector<Idx> oldPush, oldPop, push, pop;
58 std::vector<Idx>::const_iterator pushit, popit;
60 PopPushSet::const_iterator ppit;
66 for(tit = transRel.
Begin(); tit != transRel.
End(); tit++){
70 for(ppit = popPush.begin(); ppit != popPush.end(); ppit++){
74 for(popit = oldPop.begin(); popit != oldPop.end(); popit++){
77 pop.push_back(*popit);
85 oldPush = ppit->second;
86 for(pushit = oldPush.begin(); pushit != oldPush.end(); pushit++){
89 push.push_back(*pushit);
140 std::vector<StackSymbol> pop, push;
148 rPd.
SetTransition(newInitState, lambdaIdx, oldInitState, pop, push);
156 StackSymbolSet::Iterator ssit;
157 std::vector<Idx> examinedPop, examinedPush, newPop, newPush;
158 for(tit = transRel.
Begin(); tit != transRel.
End(); tit++){
164 examinedPop = rPd.
PopPush(*tit).begin()->first;
165 examinedPush = rPd.
PopPush(*tit).begin()->second;
178 newPop.push_back(*ssit);
181 newPush.insert(newPush.end(), examinedPush.begin(), examinedPush.end());
182 newPush.push_back(*ssit);
202 StateSet::Iterator stateit;
211 std::multimap<Transition, std::pair<std::vector<Idx>, std::vector<Idx> > > readSet, multiPushSet, popPushSet, unchangedSet;
212 std::multimap<Transition, std::pair<std::vector<Idx>, std::vector<Idx> > >::iterator multimapit;
213 std::pair<Transition, std::pair<std::vector<Idx>, std::vector<Idx> > > transition;
214 std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
215 std::vector<Idx> pop, push, pushEnd;
217 PopPushSet::const_iterator ppit;
229 transition = std::make_pair(*transit, *ppit);
236 readSet.insert(transition);
243 if(push.size() == 2 && push.back() == pop.front()){
244 unchangedSet.insert(transition);
250 else if(push.size() > 1){
251 if(push.back() == pop.front()){
252 multiPushSet.insert(transition);
258 popPushSet.insert(transition);
263 popPushSet.insert(transition);
268 unchangedSet.insert(transition);
273 unchangedSet.insert(transition);
284 for(multimapit = readSet.begin(); multimapit != readSet.end(); multimapit++){
288 pop = multimapit->second.first;
289 push = multimapit->second.first;
290 MergeTransition mt(multimapit->first.X1, multimapit->first.Ev, multimapit->first.X1, pop,push);
295 rPd.
SetTransition(multimapit->first.X1, multimapit->first.Ev, newState, pop, push);
297 rPd.
SetTransition(newState, lambdaIdx, multimapit->first.X2, pop, multimapit->second.second);
301 for(multimapit = multiPushSet.begin(); multimapit != multiPushSet.end(); multimapit++){
305 pop = multimapit->second.first;
306 push = std::vector<Idx>(multimapit->second.second.end() - multimapit->second.first.size() - 1, multimapit->second.second.end());
307 MergeTransition mt(multimapit->first.X1, multimapit->first.Ev, multimapit->first.X1, pop,push);
312 rPd.
SetTransition(multimapit->first.X1, multimapit->first.Ev, newState, pop, push);
315 pop.push_back(multimapit->second.second.at(multimapit->second.second.size() - multimapit->second.first.size() - 1));
316 push = std::vector<Idx>(multimapit->second.second.begin(), multimapit->second.second.end() - multimapit->second.first.size());
317 rPd.
SetTransition(newState, lambdaIdx, multimapit->first.X2, pop, push);
321 for(multimapit = popPushSet.begin(); multimapit != popPushSet.end(); multimapit++){
325 pop = multimapit->second.first;
328 MergeTransition mt(multimapit->first.X1, multimapit->first.Ev, multimapit->first.X1, pop,push);
333 rPd.
SetTransition(multimapit->first.X1, lambdaIdx, newState, pop, push);
337 push = multimapit->second.second;
338 rPd.
SetTransition(newState, lambdaIdx, multimapit->first.X2, pop, push);
342 for(multimapit = unchangedSet.begin(); multimapit != unchangedSet.end(); multimapit++){
345 pop = multimapit->second.first;
346 push= multimapit->second.second;
358 rPd.
SetTransition(multimapit->first.X1, multimapit->first.Ev, multimapit->first.X2, pop, push);
363 if(popPushSet.size() != 0){
366 else if(readSet.size() + multiPushSet.size() != 0){
377 std::cout <<
"\nPrint Transitions:\n" << std::endl;
378 std::multimap<Transition, std::pair<std::vector<StackSymbol>, std::vector<StackSymbol> > >::const_iterator transit;
379 std::vector<StackSymbol>::const_iterator ssit;
382 for(transit = transitions.begin(); transit != transitions.end(); transit++){
384 for(ssit = transit->second.first.begin(); ssit != transit->second.first.end(); ssit++){
385 s << ssit->Symbol() <<
" ";
388 for(ssit = transit->second.second.begin(); ssit != transit->second.second.end(); ssit++){
389 s << ssit->Symbol() <<
" ";
391 s <<
"]" << std::endl;
395 std::cout << s.str() << std::endl;
411 StateSet::Iterator stateit;
417 std::multimap<Transition, std::pair<std::vector<Idx>, std::vector<Idx> > > offendingTransSet;
418 std::pair<Transition, std::pair<std::vector<Idx>, std::vector<Idx> > > transition;
419 std::vector<Idx> pop, push;
420 std::set< std::pair<Idx, Idx> > intermediateStates;
421 std::pair<Idx, Idx> intermediateStatePair;
422 std::map<std::pair<Idx, Idx>,
Idx> mapIntermediateStates;
424 PopPushSet::const_iterator ppit;
434 if(ppit->first.size() > 1){
437 transition = std::make_pair(*transit, *ppit);
438 offendingTransSet.insert(transition);
442 intermediateStatePair = std::make_pair(transit->X1,ppit->first.front());
443 if(intermediateStates.insert(intermediateStatePair).second){
448 mapIntermediateStates.insert(std::make_pair(intermediateStatePair,newState));
452 pop.push_back(ppit->first.front());
462 std::multimap<Transition, std::pair<std::vector<Idx>, std::vector<Idx> > >::iterator offendingit;
463 Idx startState, intermediateState;
468 for(offendingit = offendingTransSet.begin(); offendingit != offendingTransSet.end(); offendingit++){
476 startState = offendingit->first.X1;
477 popSymbol = offendingit->second.first.front();
479 for(transit = transCopy.
Begin(startState); transit != transCopy.
End(startState); transit++){
483 ppCopy = rPd.
PopPush(*transit);
485 for(ppit = ppCopy.begin(); ppit != ppCopy.end(); ppit++){
487 if(ppit->first.front() == popSymbol && ppit->first.size() > 1){
494 intermediateState = mapIntermediateStates.find(std::make_pair(startState,popSymbol))->second;
498 pop.push_back(popSymbol);
501 rPd.
SetTransition(startState, lambdaIdx, intermediateState, pop, push);
505 pop.erase(pop.begin());
507 rPd.
SetTransition(intermediateState, transit->Ev, transit->X2, pop, push);
516 if(offendingTransSet.size() != 0){
534 StateSet::Iterator stateit;
535 Idx newStateAct, newStatePas;
536 std::string active =
"active";
537 std::string passive =
"passive";
538 std::map<Idx,std::pair<Idx,Idx> > stateMap;
564 stateMap.insert(std::make_pair(*stateit,std::make_pair(newStateAct,newStatePas)));
568 PopPushSet::const_iterator ppit;
569 std::vector<Idx> pop, push;
570 Idx startState, endState, oldStartState, oldEndState, oldEvent;
578 oldStartState = transit->X1;
579 oldEndState = transit->X2;
580 oldEvent = transit->Ev;
586 startState = stateMap.find(oldStartState)->second.first;
587 endState = stateMap.find(oldEndState)->second.first;
591 startState = stateMap.find(oldStartState)->second.second;
602 startState = stateMap.find(oldStartState)->second.second;
603 endState = stateMap.find(oldEndState)->second.second;
608 startState = stateMap.find(oldStartState)->second.first;
614 startState = stateMap.find(oldStartState)->second.first;
615 endState = stateMap.find(oldEndState)->second.first;
622 std::stringstream errstr;
623 errstr <<
"While executing Nda(): Found transition which is neither read nor pop nor push, which is not allowed" << std::endl;
624 throw Exception(
"Nda", errstr.str(), 1001);