#include#include#include#include#include#include#include#include?#define?filename?“in2.txt“using?namespace?std;ifstream?input(filename);map?>first;?//first集合map?>follow;?//follow集合map?>first_temp;map?>follow_temp;map?>string_temp;settable;?//終結符號setno_end;?//非終結符string?s[10][10];?//分析表mapxlab;mapylab;set?split(string&?strconst?char*?c)??//按|分割輸入的產生式{????char?*cstr?*p;????set?res;????cstr?=?new?char[str.size()+1];????strcpy(cstrstr.c_str());????p?=?strtok(cstrc);????while(p!=NULL)????{????????res.insert(p);????????p?=?strtok(NULLc);????}????return?res;}bool?isEnd(char?a)???//判斷是否是終結符{????if(a>=‘A‘?&&?a<=‘Z‘)????????return?false;????else????????return?true;}/*void?EndAndNoEnd(){????string?temp;????string?temp1;????set?temp2;????map?all_temp;????unsigned?int?start?=?0;????while(getline(inputtemp))????{????????cout<????????all_temp[temp[0]]?=?temp;????}????map::iterator?iter1=all_temp.begin();????int?all_size?=?all_temp.size();????for(int?i?=?0;i?????{????????temp?=?iter1->second;????????no_end.insert(temp[0]);????????int?len?=?temp.length();????????temp1?=?temp.substr(5len?-?5);????????temp2?=?split(temp1“?|?“);????????set::iterator?ite1?=?temp2.begin();????????set::iterator?ite2?=?temp2.end();????????//if(first.find(temp[0])==first.end())????????for(;ite1!=ite2;ite1++)????????{????????????int?maxt?=?(*ite1).length();????????????for(int?j?=?;j????????????{????????????????if(isEnd((*ite1)[j]))????????????????????table.insert((*ite1)[j]);????????????}????????}????}}*/void?First(){????string?temp;????string?temp1;????set?temp2;????map?all_temp;???//輸入的所有產生式????unsigned?int?start?=?0;????while(getline(inputtemp))????{????????cout<????????all_temp[temp[0]]?=?temp;????}????map::iterator?iter1=all_temp.begin();????int?all_size?=?all_temp.size();????for(int?i?=?0;i?????{????????temp?=?iter1->second;????????int?len?=?temp.length();????????temp1?=?temp.substr(5len?-?5);????????temp2?=?split(temp1“?|?“);????????set::iterator?ite1?=?temp2.begin();????????set::iterator?ite2?=?temp2.end();????????//if(first.find(temp[0])==first.end())????????for(;ite1!=ite2;ite1++)????????{????????????//cout<<*ite1<????????????start?=?0;????????????if(isEnd((*ite1)[start]))????????????????first[temp[0]].insert((*ite1)[start]);????????????else????????????{????????????????first_temp[temp[start]].insert((*ite1)[start]);????????????????while(start+1<(*ite1).length())??????????????
共有 條評論