#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 < all_size;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 < all_size;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())
共有 条评论
评论
共有 条评论