資源描述:
《編譯原理 非遞歸預(yù)測分析法.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、附:代碼#include#include#include#includeusingnamespacestd;#definestacksize10#definestringsize20typedefstructsqst//定義分析棧{intdata[stacksize];inttop;//棧頂指針}sqstack;stringword1[]={"prgm","prgm'","expr","term","expr'","factor","term'","system_goal"};stringwor
2、d2[]={"#",";","+","*","(",")","NUM"};intmain(){voidout(sqstackst,stringstr,intsp,intk);//輸出函數(shù)voidinit(intYy_pushtab[13][4],intYy_d[264][7]);//初始化分析棧Yy_d[]與Yy_pushtab[]voidstr_to_st1(stringstr,intst1[]);//對輸入字符串的轉(zhuǎn)換voidForeparser(sqstackst,intYy_pushtab[13][4],intYy_d[264][7],intst1[],st
3、ringstr);//預(yù)測分析法intYy_pushtab[13][4],Yy_d[264][7];intst1[stringsize];stringstr;sqstackst;st.top=-1;//分析棧的初始化st.top++;st.data[st.top]=263;//分析棧初始化"#"cout<<"請輸入字符串:";cin>>str;cout<<"棧(符號)"<<"棧(數(shù)值)"<<"輸入串"<<"What_to_do"<4、tab,Yy_d,st1,str);return0;}voidout(sqstackst,stringstr,intsp,intk)//輸出函數(shù){intn,m=0;for(inti=0;i<=sp;i++)//輸出棧(符號){if(st.data[i]<7){cout<5、)cout<<"";for(i=0;i<=sp;i++)//輸出棧(數(shù)字)cout<6、初始化分析棧Yy_d[]與Yy_pushtab[]{inti,j;ifstreaminfile1("1.txt",ios::in);ifstreaminfile2("2.txt",ios::in);for(i=0;i<13;i++){for(j=0;j<4;j++){infile1>>Yy_pushtab[i][j];//cout<>Yy_d[i][j];//cout<7、//cout<