21 std::set<Idx> successorStates;
28 if(*gotoGen.
Symbol(*transit) == *symbol){
29 successorStates.insert(transit->X2);
32 return successorStates;
42 std::vector<Idx> rStateSequence;
51 if(*word.front() != *lambda){
58 std::set<Idx> nextStateSet =
GeneratorGoto(gotoGen, startState, frontSymbol);
60 if(!nextStateSet.empty()){
61 nextState = *nextStateSet.begin();
64 rStateSequence.push_back(nextState);
68 std::vector<Idx> remainingSequence =
GeneratorGotoSeq(gotoGen, nextState, remainingWord);
71 rStateSequence.insert(rStateSequence.end(), remainingSequence.begin(), remainingSequence.end());
74 return rStateSequence;
83 std::set<Lr1ParserAction> rActions;
89 StateSet::Iterator stateit;
93 std::set<Terminal>::const_iterator tit;
107 std::set<Idx> succStateSet =
GeneratorGoto(gotoGen, *stateit, aPtr);
111 if(succStateSet.size() != 1){
116 Idx succState = *succStateSet.begin();
118 std::set<Lr1Configuration>::const_iterator configit;
120 for(configit = gotoGen.
ConfigSet(*stateit).begin(); configit != gotoGen.
ConfigSet(*stateit).end(); configit++){
128 beforeDot = configit->BeforeDot();
129 if(**beforeDot.begin() == *lambda){
132 afterDot = configit->AfterDot();
133 if(**afterDot.begin() == *lambda){
139 rhs.insert(rhs.end(), afterDot.begin(), afterDot.end());
141 rhs.push_back(lambdaPtr);
157 if(!configit->Lookahead().IsLambda()){
160 w2z.push_back(lookaheadPtr);
164 std::set<Terminal> firstTerminals =
FirstLeq1(augGr, k - 1, w2z);
166 std::set<Terminal>::const_iterator firsttit;
168 for(firsttit = firstTerminals.begin(); firsttit != firstTerminals.end(); firsttit++){
171 if(!firsttit->IsLambda()){
172 std::stringstream errstr;
173 errstr <<
"While executing LrpRules(): Constructing shift actions and the terminal " << firsttit->Str() <<
", which was expected to be lambda" << std::endl;
174 throw Exception(
"LrpRules", errstr.str(), 1001);
179 std::vector<Idx> stateStack;
180 stateStack.push_back(*stateit);
184 stateStack.push_back(succState);
190 rActions.insert(action);
204 std::set<Lr1ParserAction> rActions;
209 StateSet::Iterator stateit;
213 std::set<Lr1Configuration>::const_iterator configit;
215 for(configit = gotoGen.
ConfigSet(*stateit).begin(); configit != gotoGen.
ConfigSet(*stateit).end(); configit++){
219 if(**configit->BeforeDot().begin() != *lambda){
232 std::set<Idx> succStateSet =
GeneratorGoto(gotoGen, *stateit, aPtr);
235 if(succStateSet.size() != 1){
238 Idx succState = *succStateSet.begin();
241 std::vector<Idx> succStateSequence =
GeneratorGotoSeq(gotoGen, *stateit, configit->AfterDot());
244 std::vector<Idx> qQs;
245 qQs.push_back(*stateit);
246 qQs.insert(qQs.end(), succStateSequence.begin(), succStateSequence.end());
249 Idx lastState = qQs.back();
251 std::set<Lr1Configuration>::const_iterator lsconfigit;
253 for(lsconfigit = gotoGen.
ConfigSet(lastState).begin(); lsconfigit != gotoGen.
ConfigSet(lastState).end(); lsconfigit++){
256 if(lsconfigit->Lhs() != configit->Lhs()){
259 if(!
EqualsGsVector(lsconfigit->BeforeDot(), configit->AfterDot())){
262 if(**lsconfigit->AfterDot().begin() != *lambda){
267 Terminal lookahead(lsconfigit->Lookahead());
274 std::vector<Idx> stateStack;
275 stateStack.push_back(*stateit);
276 stateStack.push_back(succState);
282 rActions.insert(action);
295 std::set<Lr1ParserAction> rActions;
301 std::set<Lr1ParserAction> reduceActions =
LrpReduceRules(gr, augGr, gotoGen, k);
302 rActions.insert(reduceActions.begin(), reduceActions.end());
328 word.push_back(augSymbolPtr);
329 word.push_back(q0Ptr);
333 word.push_back(augSymbolPtr);
337 if(!succStateSetAug.empty() && !succStateSeqAugQ0.empty() && !succStateSeqAugQ0Aug.empty()){
340 Idx succStateAug = *succStateSetAug.begin();
343 Idx lastStateAugQ0 = succStateSeqAugQ0.back();
346 Idx lastStateAugQ0Aug = succStateSeqAugQ0Aug.back();
348 StateSet::Iterator stateit;
352 if(*stateit != gotoGen.
InitState() && *stateit != lastStateAugQ0Aug){
357 std::set<Terminal>::const_iterator tit;
370 std::set<Lr1ParserAction> actions =
LrpRules(gr, augGr, gotoGen, k);
372 std::set<Lr1ParserAction>::const_iterator actit;
374 for(actit = actions.begin(); actit != actions.end(); actit++){
393 std::set<Idx>::const_iterator ntit;
394 std::set<Terminal>::const_iterator tit;
395 std::map<std::pair<Idx,Idx>,
Idx> stateMap;
396 std::map<std::pair<Idx,Idx>,
Idx>::const_iterator statemapit;
408 if(parser.
StartState() == *ntit && tit->IsLambda()){
412 else if(parser.
FinalState() == *ntit && tit->IsLambda()){
425 std::pair<Idx,Idx> key = std::make_pair(*ntit, tit->Event());
426 stateMap.insert(std::make_pair(key, newState));
453 statemapit = stateMap.find(finalState);
455 std::set<Lr1ParserAction>::const_iterator actit;
457 for(actit = parser.
Actions().begin(); actit != parser.
Actions().end(); actit++){
466 std::stringstream errstr;
467 errstr <<
"While executing Gp2Pp(): Tried to create transition from parser action " << actit->
Str() <<
", but no rule exists for converting transitions with lambda in the left-hand side's next terminal. " << std::endl;
468 throw Exception(
"Gp2Pp", errstr.str(), 1001);
484 statemapit = stateMap.find(std::make_pair(stateA,eventLambda));
485 if(statemapit == stateMap.end()){
486 std::stringstream errstr;
487 errstr <<
"While executing Gp2Pp(): Tried to find a pushdown generator state for the pair of goto generator state " << stateA <<
" and parser terminal " << eventLambda <<
" (" << rhs.
NextTerminal().
Str() <<
"), but could not be found." << std::endl;
488 throw Exception(
"Gp2Pp", errstr.str(), 1001);
490 Idx aLambda = statemapit->second;
493 statemapit = stateMap.find(std::make_pair(stateB,eventLambda));
494 if(statemapit == stateMap.end()){
495 std::stringstream errstr;
496 errstr <<
"While executing Gp2Pp(): Tried to find a pushdown generator state for the pair of goto generator state " << stateB <<
" and parser terminal " << eventLambda <<
" (" << rhs.
NextTerminal().
Str() <<
"), but could not be found." << std::endl;
497 throw Exception(
"Gp2Pp", errstr.str(), 1001);
499 Idx bLambda = statemapit->second;
502 statemapit = stateMap.find(std::make_pair(stateA,eventA));
503 if(statemapit == stateMap.end()){
504 std::stringstream errstr;
505 errstr <<
"While executing Gp2Pp(): Tried to find a pushdown generator state for the pair of goto generator state " << stateA <<
" and parser terminal " << eventA <<
" (" << lhs.
NextTerminal().
Str() <<
"), but could not be found." << std::endl;
506 throw Exception(
"Gp2Pp", errstr.str(), 1001);
508 Idx aA = statemapit->second;
511 std::vector<StackSymbol> popLambda, pushA;
518 rPd.
SetTransition(aLambda, eventA, bLambda, popLambda, pushA);
521 rPd.
SetTransition(aA, eventLambda, bLambda, popLambda, pushA);
538 std::vector<Idx> statesW;
545 statemapit = stateMap.find(std::make_pair(stateB,eventLambda));
546 if(statemapit == stateMap.end()){
547 std::stringstream errstr;
548 errstr <<
"While executing Gp2Pp(): Tried to find a pushdown generator state for the pair of goto generator state " << stateB <<
" and parser terminal " << eventLambda <<
" (" <<
FAUDES_PD_LAMBDA <<
"), but could not be found." << std::endl;
549 throw Exception(
"Gp2Pp", errstr.str(), 1001);
551 Idx bLambda = statemapit->second;
554 statemapit = stateMap.find(std::make_pair(stateC,eventY));
555 if(statemapit == stateMap.end()){
556 std::stringstream errstr;
557 errstr <<
"While executing Gp2Pp(): Tried to find a pushdown generator state for the pair of goto generator state " << stateC <<
" and parser terminal " << eventY <<
" (" << lhs.
NextTerminal().
Str() <<
"), but could not be found." << std::endl;
558 throw Exception(
"Gp2Pp", errstr.str(), 1001);
560 Idx cY = statemapit->second;
563 statemapit = stateMap.find(std::make_pair(stateB,eventY));
564 if(statemapit == stateMap.end()){
565 std::stringstream errstr;
566 errstr <<
"While executing Gp2Pp(): Tried to find a pushdown generator state for the pair of goto generator state " << stateB <<
" and parser terminal " << eventY <<
" (" << lhs.
NextTerminal().
Str() <<
"), but could not be found." << std::endl;
567 throw Exception(
"Gp2Pp", errstr.str(), 1001);
569 Idx bY = statemapit->second;
572 std::vector<StackSymbol> popWA, pushA;
573 std::vector<Idx>::const_reverse_iterator idxit;
574 for(idxit = statesW.rbegin(); idxit != statesW.rend(); idxit++){
600 std::stringstream errstr;
601 errstr <<
"While executing Gp2Pp(): Tried to create transition from parser action " << actit->Str() <<
", but no rule exists for converting it. It seems to be neither a shift nor a reduce action. " << std::endl;
602 throw Exception(
"Aug", errstr.str(), 1001);
619 PopPushSet::const_iterator ppit;
624 if(transit->Ev == augSymbol.
Event()){