18 std::string name =
"Filter Mixed Grammar Symbols";
24 std::set<Terminal>::const_iterator tit;
25 std::vector<TerminalPtr> tpv;
26 std::vector<TerminalPtr>::iterator tpvit;
27 std::set<Nonterminal> rSet;
34 word.push_back(ntPtr);
49 std::stringstream errstr;
50 errstr <<
"size of result set is " << rSet.size() <<
", but 1 was expected" << std::endl;
51 throw Exception(name, errstr.str(), 1003);
56 std::stringstream errstr;
57 errstr <<
"result set did not contain the expected nonterminal " << gr1.
Nonterminals().begin()->Str() << std::endl;
58 throw Exception(name, errstr.str(), 1003);
62 std::cout << (*rSet.begin()).Str() << std::endl;
63 std::cout << (*gr1.
Nonterminals().begin()).Str() << std::endl;
73 std::string name =
"Filter Nothing";
76 std::set<Nonterminal> nt;
79 std::set<Nonterminal> rSet =
Filter(nt,gs);
84 std::stringstream errstr;
85 errstr <<
"size of result set is " << rSet.size() <<
", but 0 was expected" << std::endl;
86 throw Exception(name, errstr.str(), 1003);
99 std::string name =
"Rnpp1 Find Symbols Empty Set";
110 std::cout <<
"Warning, test parameters seem to be wrong. The test grammar did not contain Nonterminal (5,[3],1)." << std::endl;
115 std::set<Nonterminal> ntSet;
117 std::set<Nonterminal> rSet =
Rnpp1(gr,ntSet);
121 if(rSet.size() != 1){
122 std::stringstream errstr;
123 errstr <<
"size of result set is " << rSet.size() <<
", but 1 was expected" << std::endl;
124 throw Exception(name, errstr.str(), 1003);
127 if(*rSet.begin() != nt){
128 std::stringstream errstr;
129 errstr <<
"result set did not contain the expected nonterminal " << nt.
Str() << std::endl;
130 throw Exception(name, errstr.str(), 1003);
143 std::string name =
"Rnpp1 Find Symbols Empty Set";
154 std::cout <<
"Warning, test parameters seem to be wrong. The test grammar did not contain Nonterminal (1,[2],2)." << std::endl;
155 std::cout << gr.
Str() << std::endl;
160 std::set<Nonterminal> ntSet;
162 std::set<Nonterminal> rSet =
Rnpp1(gr,
Rnpp1(gr,ntSet));
166 if(rSet.size() != 2){
167 std::stringstream errstr;
168 errstr <<
"size of result set is " << rSet.size() <<
", but 2 was expected" << std::endl;
169 throw Exception(name, errstr.str(), 1003);
172 if(*rSet.begin() != nt){
173 std::stringstream errstr;
174 errstr <<
"result set did not contain the expected nonterminal " << nt.
Str() << std::endl;
175 throw Exception(name, errstr.str(), 1003);
188 std::string name =
"Rnppl Find Symbols Empty Set";
200 std::set<Nonterminal> ntSet;
202 std::set<Nonterminal> rSet =
Rnppl(gr,ntSet);
206 if(rSet.size() != findThis.size()){
207 std::stringstream errstr;
208 errstr <<
"size of result set is " << rSet.size() <<
", but " << findThis.size() <<
" was expected" << std::endl;
209 throw Exception(name, errstr.str(), 1003);
212 std::set<Nonterminal>::const_iterator ntit, findit;
213 for(ntit = findThis.begin(); ntit != findThis.end(); ntit++){
215 findit = rSet.find(*ntit);
217 if(findit == findThis.end()){
218 std::stringstream errstr;
219 errstr <<
"result set did not contain the expected nonterminal " << ntit->Str() << std::endl;
220 throw Exception(name, errstr.str(), 1003);
234 std::string name =
"Rnppl Find Symbols Nonempty Set";
246 std::set<Nonterminal> ntSet;
247 v.clear(); v.push_back(2);
249 v.clear(); v.push_back(3);
252 std::set<Nonterminal> rSet =
Rnppl(gr,ntSet);
256 if(rSet.size() != findThis.size()){
257 std::stringstream errstr;
258 errstr <<
"size of result set is " << rSet.size() <<
", but " << findThis.size() <<
" was expected" << std::endl;
259 throw Exception(name, errstr.str(), 1003);
262 std::set<Nonterminal>::const_iterator ntit, findit;
263 for(ntit = findThis.begin(); ntit != findThis.end(); ntit++){
265 findit = rSet.find(*ntit);
267 if(findit == findThis.end()){
268 std::stringstream errstr;
269 errstr <<
"result set did not contain the expected nonterminal " << ntit->Str() << std::endl;
270 throw Exception(name, errstr.str(), 1003);
284 std::string name =
"Rnppl Find Symbols Complete Set";
296 std::set<Nonterminal> ntSet = findThis;
298 std::set<Nonterminal> rSet =
Rnppl(gr,ntSet);
302 if(rSet.size() != findThis.size()){
303 std::stringstream errstr;
304 errstr <<
"size of result set is " << rSet.size() <<
", but " << findThis.size() <<
" was expected" << std::endl;
305 throw Exception(name, errstr.str(), 1003);
308 std::set<Nonterminal>::const_iterator ntit, findit;
309 for(ntit = findThis.begin(); ntit != findThis.end(); ntit++){
311 findit = rSet.find(*ntit);
313 if(findit == findThis.end()){
314 std::stringstream errstr;
315 errstr <<
"result set did not contain the expected nonterminal " << ntit->Str() << std::endl;
316 throw Exception(name, errstr.str(), 1003);
330 std::string name =
"Rnpp Grammar 1";
346 v.clear(); v.push_back(2);
354 std::stringstream errstr;
355 errstr <<
"size of nonterminal set is " << rGr.
Nonterminals().size() <<
", but " << finalNtSet.size() <<
" was expected" << std::endl;
356 throw Exception(name, errstr.str(), 1003);
360 std::stringstream errstr;
361 errstr <<
"size of grammar production set is " << rGr.
GrammarProductions().size() <<
", but " << finalGpSet.size() <<
" was expected" << std::endl;
362 throw Exception(name, errstr.str(), 1003);
366 std::set<Nonterminal>::const_iterator ntit, findntit;
367 for(ntit = finalNtSet.begin(); ntit != finalNtSet.end(); ntit++){
371 if(findntit == finalNtSet.end()){
372 std::stringstream errstr;
373 errstr <<
"nonterminal set did not contain the expected nonterminal " << ntit->Str() << std::endl;
374 throw Exception(name, errstr.str(), 1003);
379 std::set<GrammarProduction>::const_iterator gpit, findgpit;
380 for(gpit = finalGpSet.begin(); gpit != finalGpSet.end(); gpit++){
384 if(findgpit == finalGpSet.end()){
385 std::stringstream errstr;
386 errstr <<
"grammar productions set did not contain the expected grammar production " << gpit->Str() << std::endl;
387 throw Exception(name, errstr.str(), 1003);
401 std::string name =
"Rnpp Grammar 2";
428 std::stringstream errstr;
429 errstr <<
"size of nonterminal set is " << rGr.
Nonterminals().size() <<
", but " << finalNtSet.size() <<
" was expected" << std::endl;
430 throw Exception(name, errstr.str(), 1003);
434 std::stringstream errstr;
435 errstr <<
"size of grammar production set is " << rGr.
GrammarProductions().size() <<
", but " << finalGpSet.size() <<
" was expected" << std::endl;
436 throw Exception(name, errstr.str(), 1003);
440 std::set<Nonterminal>::const_iterator ntit, findntit;
441 for(ntit = finalNtSet.begin(); ntit != finalNtSet.end(); ntit++){
445 if(findntit == finalNtSet.end()){
446 std::stringstream errstr;
447 errstr <<
"nonterminal set did not contain the expected nonterminal " << ntit->Str() << std::endl;
448 throw Exception(name, errstr.str(), 1003);
453 std::set<GrammarProduction>::const_iterator gpit, findgpit;
454 for(gpit = finalGpSet.begin(); gpit != finalGpSet.end(); gpit++){
458 if(findgpit == finalGpSet.end()){
459 std::stringstream errstr;
460 errstr <<
"grammar productions set did not contain the expected grammar production " << gpit->Str() << std::endl;
461 throw Exception(name, errstr.str(), 1003);
475 std::string name =
"Rnpp Empty Grammar";
485 std::stringstream errstr;
486 errstr <<
"size of nonterminal set is " << rGr.
Nonterminals().size() <<
", but 0 was expected" << std::endl;
487 throw Exception(name, errstr.str(), 1003);
491 std::stringstream errstr;
492 errstr <<
"size of grammar production set is " << rGr.
GrammarProductions().size() <<
", but 0 was expected" << std::endl;
493 throw Exception(name, errstr.str(), 1003);
506 std::string name =
"Sp2Lr Terminals";
516 std::stringstream errstr;
517 errstr <<
"size of terminal set is " << gr.
Terminals().size() <<
", but "<< g.
Alphabet().Size() <<
" was expected" << std::endl;
518 throw Exception(name, errstr.str(), 1003);
521 EventSet::Iterator eventit;
525 std::stringstream errstr;
526 errstr <<
"terminal " << g.
EventName(*eventit) <<
" was not found in terminal set" << std::endl;
527 throw Exception(name, errstr.str(), 1003);
541 std::string name =
"Sp2Lr Nonterminals";
552 if(expectedNumberNonterminals != gr.
Nonterminals().size()){
553 std::stringstream errstr;
554 errstr <<
"size of nonterminal set is " << gr.
Nonterminals().size() <<
", but "<< expectedNumberNonterminals <<
" was expected" << std::endl;
555 throw Exception(name, errstr.str(), 1003);
560 std::stringstream errstr;
561 errstr <<
"start symbol was " << gr.
StartSymbol().
Str() <<
", but (2, [square]) was expected" << std::endl;
562 throw Exception(name, errstr.str(), 1003);
575 std::string name =
"Sp2Lr Productions";
582 std::vector<Idx> dot, lambda, square;
619 std::set<GrammarProduction> read;
622 v.push_back(nt1dot1Ptr);
626 v.push_back(nt1dot2Ptr);
630 v.push_back(nt1dotPtr);
634 std::set<GrammarProduction> pop;
636 v.push_back(tlambdaPtr);
640 std::set<GrammarProduction> push;
642 v.push_back(nt2dot1Ptr);
643 v.push_back(nt1square1Ptr);
646 v.push_back(nt2dot2Ptr);
647 v.push_back(nt2square1Ptr);
650 v.push_back(nt2dot1Ptr);
651 v.push_back(nt1square2Ptr);
654 v.push_back(nt2dot2Ptr);
655 v.push_back(nt2square2Ptr);
658 v.push_back(nt2dot1Ptr);
659 v.push_back(nt1squarePtr);
662 v.push_back(nt2dot2Ptr);
663 v.push_back(nt2squarePtr);
666 v.push_back(nt2dotPtr);
670 std::set<GrammarProduction>
final;
672 v.push_back(tlambdaPtr);
675 v.push_back(tlambdaPtr);
682 std::set<GrammarProduction>::const_iterator gpit;
684 for(gpit = read.begin(); gpit != read.end(); gpit++){
685 if(gp.erase(*gpit) == 0){
686 std::stringstream errstr;
687 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a read transition, was expected but not found in the grammar" << std::endl;
688 throw Exception(name, errstr.str(), 1003);
693 for(gpit = pop.begin(); gpit != pop.end(); gpit++){
694 if(gp.erase(*gpit) == 0){
695 std::stringstream errstr;
696 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a pop transition, was expected but not found in the grammar" << std::endl;
697 throw Exception(name, errstr.str(), 1003);
702 for(gpit = push.begin(); gpit != push.end(); gpit++){
703 if(gp.erase(*gpit) == 0){
704 std::stringstream errstr;
705 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a push transition, was expected but not found in the grammar" << std::endl;
706 throw Exception(name, errstr.str(), 1003);
711 for(gpit =
final.begin(); gpit !=
final.end(); gpit++){
712 if(gp.erase(*gpit) == 0){
713 std::stringstream errstr;
714 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a final transition, was expected but not found in the grammar" << std::endl;
715 throw Exception(name, errstr.str(), 1003);
721 std::stringstream errstr;
722 errstr <<
"the grammar contained" << gp.size() <<
" more productions than expected" << std::endl;
723 throw Exception(name, errstr.str(), 1003);
736 std::string name =
"Sp2Lr2 Productions";
743 std::vector<Idx> dot, lambda, square;
780 std::set<GrammarProduction> read;
783 v.push_back(nt1dot2Ptr);
787 std::set<GrammarProduction> pop;
789 v.push_back(tlambdaPtr);
793 std::set<GrammarProduction> push;
795 v.push_back(nt2dot2Ptr);
796 v.push_back(nt2squarePtr);
799 v.push_back(nt2dotPtr);
803 std::set<GrammarProduction>
final;
805 v.push_back(tlambdaPtr);
808 v.push_back(tlambdaPtr);
814 std::set<GrammarProduction>::const_iterator gpit;
816 for(gpit = read.begin(); gpit != read.end(); gpit++){
817 if(gp.erase(*gpit) == 0){
818 std::stringstream errstr;
819 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a read transition, was expected but not found in the grammar" << std::endl;
820 throw Exception(name, errstr.str(), 1003);
825 for(gpit = pop.begin(); gpit != pop.end(); gpit++){
826 if(gp.erase(*gpit) == 0){
827 std::stringstream errstr;
828 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a pop transition, was expected but not found in the grammar" << std::endl;
829 throw Exception(name, errstr.str(), 1003);
834 for(gpit = push.begin(); gpit != push.end(); gpit++){
835 if(gp.erase(*gpit) == 0){
836 std::stringstream errstr;
837 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a push transition, was expected but not found in the grammar" << std::endl;
838 throw Exception(name, errstr.str(), 1003);
843 for(gpit =
final.begin(); gpit !=
final.end(); gpit++){
844 if(gp.erase(*gpit) == 0){
845 std::stringstream errstr;
846 errstr <<
"grammar production " << gpit->Str() <<
" , which is generated by a final transition, was expected but not found in the grammar" << std::endl;
847 throw Exception(name, errstr.str(), 1003);
853 std::stringstream errstr;
854 errstr <<
"the grammar contained" << gp.size() <<
" more productions than expected" << std::endl;
855 throw Exception(name, errstr.str(), 1003);
868 std::string name =
"Test Rup Productions";
878 std::stringstream errstr;
880 throw Exception(name, errstr.str(), 1003);
894 gs.push_back(nt2Ptr);
898 std::stringstream errstr;
899 errstr <<
"grammar production (2, [dot], 2) -> a(1, [dot]) was present, but was expected to be deleted" << std::endl;
900 throw Exception(name, errstr.str(), 1003);
913 std::string name =
"Test Rup Nonterminals";
923 std::stringstream errstr;
924 errstr <<
"size of nonterminals was " << rGr.
Nonterminals().size() <<
", but " << gr.
Nonterminals().size() - 1 <<
" was expected" << std::endl;
925 throw Exception(name, errstr.str(), 1003);
933 std::stringstream errstr;
934 errstr <<
"nonterminal (2, [dot], 2) was present, but was expected to be deleted" << std::endl;
935 throw Exception(name, errstr.str(), 1003);