




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、實(shí) 驗(yàn) 報(bào) 告實(shí)驗(yàn)項(xiàng)目列表序號(hào)實(shí)驗(yàn)項(xiàng)目名稱成績01DFA的生成與字符串的識(shí)別02程序段的單詞識(shí)別03自頂向下語法分析方法的實(shí)現(xiàn)04050607080910111213141516總評(píng)成績: 教員簽字:一、 實(shí)驗(yàn)名稱自頂向下語法分析方法的實(shí)現(xiàn)二、實(shí)驗(yàn)?zāi)康?.掌握自頂向下語法分析的方法; 2.運(yùn)用編程的手段實(shí)現(xiàn)自頂向下語法分析。三、實(shí)驗(yàn)內(nèi)容和要求四、實(shí)驗(yàn)環(huán)境1硬件環(huán)境:PC機(jī)2軟件環(huán)境:Windows操作系統(tǒng),VC+集成開發(fā)環(huán)境五、算法設(shè)計(jì)思想六、主要問題與解決方法七、實(shí)驗(yàn)結(jié)果以下是程序的用戶運(yùn)行界面截圖:八、體會(huì)、質(zhì)疑、建議九、源代碼 #include<fstream>#includ
2、e<sstream>#include<iostream>#include<vector>#include<string>#include<windows.h>#include<iterator>#include<algorithm>#include<stdlib.h>#define M 20using namespace std;void gotoxy(int x,int y)COORD coord;coord.X=x;coord.Y=y;SetConsoleCursorPosition( GetS
3、tdHandle( STD_OUTPUT_HANDLE ), coord );class tablepublic:void read();friend class an_process;string find_str(char row,char col);private:string matrixMM;char start;vector<string> vec_row;vector<string> vec_col;class sentencepublic:void read_in();friend class an_process;private:string str_
4、input;class an_processpublic:void analyse(const table LL1_table,const sentence input);void write_result();void print2(int x,int y);private:vector<int> step;vector<vector<char> > stack_note;vector<string> remain;vector<string> production;void table:read()string a,str;cha
5、r x,y;int linenum = 0;char line1024=0;ifstream infile("table1.txt");if(!infile)cerr<<"錯(cuò)誤!無法存儲(chǔ)用戶數(shù)據(jù)!n"while(infile.getline(line,sizeof(line)stringstream word(line);if(linenum>1)if(word>>x&&word>>y&&word>>str)matrixx-48y-48=str;/*cout<&l
6、t;x<<" "cout<<y<<" "cout<<matrixx-48y-48<<" "*/while(word>>a&&linenum<2)if(linenum=0)vec_col.push_back(a);/*cout<<a<<" "*/else if(linenum=1)vec_row.push_back(a);/*cout<<a<<" "*/*c
7、out<<endl;*/linenum+;start=vec_col00;/*for(int icnt=0;icnt<vec_col.size();icnt+)cout<<vec_colicnt<<" "*/string table:find_str(char row,char col)for(int x=0;x<vec_col.size();x+)for(int y=0;y<vec_row.size();y+)if(row=vec_colx0&&col=vec_rowy0)return matrixx+
8、1y+1;return ""void an_process:analyse(table LL1_table,sentence input)int icnt=0,jcnt=0,kcnt;string ac,prod="",re=""vector<char> stack;char Now_word=input.str_inputicnt;char NOW_state=LL1_table.start;string:const_iterator Eiter;string:const_iterator Biter;stack.pus
9、h_back('#');stack.push_back(NOW_state);for(;icnt<input.str_input.size();)step.push_back(+jcnt);stack_note.push_back(stack);for(kcnt=icnt;kcnt<input.str_input.size();kcnt+)re=re+input.str_inputkcnt;re=re+"#"remain.push_back(re);re.erase();Now_word=input.str_inputicnt;NOW_state
10、=stack.back();if(NOW_state=Now_word)stack.erase(stack.end()-1);icnt+;production.push_back("(匹配)");elseac=LL1_table.find_str(NOW_state,Now_word);Biter=ac.begin();Biter-;Eiter=ac.end();Eiter-;if(ac="")prod=prod+NOW_state;prod=prod+""prod=prod+""stack.erase(stack
11、.end()-1);production.push_back(prod);prod.erase();else if(ac!="")stack.erase(stack.end()-1);prod.empty();prod=prod+NOW_state;prod=prod+""+ac;production.push_back(prod);prod.erase();for(;Eiter!=Biter;Eiter-)stack.push_back(*Eiter);else cout<<"分析失敗n"exit(0);if(stack
12、.size()!=1|stack.back()!='#')cout<<"分析失敗n"exit(0);void an_process:write_result()step.push_back(step.back()+1);vector<char> a;a.push_back('#');stack_note.push_back(a);remain.push_back("#");production.push_back("接受");gotoxy(27,1);cout<<&q
13、uot;輸入串"<<'"'<<remain0;cout<<"b"<<'"'<<"的分析過程"<<endl<<endl;print2(step.size()+1,4);vector<int>:const_iterator iter1=step.begin();vector<vector<char> >:const_iterator iter2=stack_note.begin(
14、);vector<string>:const_iterator iter3=remain.begin();vector<string>:const_iterator iter4=production.begin();gotoxy(8,4);cout<<"步驟"gotoxy(27,4);cout<<"分析棧"gotoxy(44,4);cout<<"剩余輸入串"gotoxy(63,4);cout<<"所用產(chǎn)生式"for(int xy=0;iter1
15、!=step.end();iter1+)gotoxy(9,xy+6);cout<<(*iter1);xy=xy+2;for(xy=0;iter2!=stack_note.end();iter2+)gotoxy(27,xy+6);for(int icnt=0;icnt<(*iter2).size();icnt+)cout<<(*iter2)icnt;xy=xy+2;for(xy=0;iter3!=remain.end();iter3+)gotoxy(44,xy+6);cout<<(*iter3);xy=xy+2;for(xy=0;iter4!=produ
16、ction.end();iter4+)gotoxy(63,xy+6);cout<<(*iter4);xy=xy+2;cout<<endl<<endl;void an_process:print2(int x,int y)/簡易畫線代碼,呵呵,畫行直線int i,j;for(int icnt=0;icnt<y-1;icnt+)for(i=0;i<37/y;i+)printf("");printf("");for(i=0;i<37/y;i+)printf("");putchar(10)
17、;for(icnt=0;icnt<y-1;icnt+)for(i=0;i<37/y;i+)printf(" ");printf("");putchar(10);for(j=0;j<x-1;j+)/畫5行直線for(icnt=0;icnt<y-1;icnt+)for(i=0;i<37/y;i+)printf("");printf("");for(i=0;i<37/y;i+)printf("");putchar(10);for(icnt=0;icnt<y-1;icnt+)for(i=0;i<37/y;i+)printf(" ");printf("");putchar(10);for(icnt=0;icnt<y-1;icnt+)for(i=0;i<37/y;i+)printf("");printf("");for(i=0;i<
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 寵物行業(yè)用友t3進(jìn)銷存操作流程他
- 高校英語核心素養(yǎng)培養(yǎng)心得體會(huì)
- 學(xué)校2025少先隊(duì)志愿服務(wù)計(jì)劃
- 河道淤積清理環(huán)境保護(hù)方案及措施
- 2025年職業(yè)學(xué)校健康安全教育計(jì)劃
- 學(xué)習(xí)《銷售人員違反職業(yè)道德行為處理辦法》心得體會(huì)
- 醫(yī)美護(hù)理潔面服務(wù)流程設(shè)計(jì)
- 西師版五年級(jí)數(shù)學(xué)下冊(cè)教學(xué)反思計(jì)劃
- 紅色研學(xué)心得體會(huì)報(bào)告
- IT硬件物料控制流程
- 火鍋店領(lǐng)班的崗位職責(zé)和工作流程
- 基恩士靜電測量儀說明書
- 健康照護(hù)師(初級(jí))理論知識(shí)考核試題
- 工程量確認(rèn)單
- 鐵總物資〔2015〕117號(hào):鐵路建設(shè)項(xiàng)目甲供物資目錄
- 人教版高中物理必修一全套課件【精品】
- GA/T 2066-2023法庭科學(xué)生物檢材中甲嘧磺隆等21種磺酰脲類除草劑篩選液相色譜-質(zhì)譜法
- 《建筑工程碳排放計(jì)量》-課件-第5章-建筑碳排放實(shí)例分析
- DL5168-2023年110KV-750KV架空輸電線路施工質(zhì)量檢驗(yàn)及評(píng)定規(guī)程
- 2023年副主任醫(yī)師(副高)-疾病控制(副高)考試歷年真題集錦答案附后
- 地下礦山基建期應(yīng)急預(yù)案
評(píng)論
0/150
提交評(píng)論