




版權(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 北京市西城區(qū)2025年三年級(jí)數(shù)學(xué)第二學(xué)期期末監(jiān)測模擬試題含解析
- 貴州黔南經(jīng)濟(jì)學(xué)院《批判性閱讀與寫作》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西工商學(xué)院《課堂教學(xué)技能訓(xùn)練》2023-2024學(xué)年第二學(xué)期期末試卷
- 浙江紡織服裝職業(yè)技術(shù)學(xué)院《插花藝術(shù)》2023-2024學(xué)年第一學(xué)期期末試卷
- 南京工業(yè)大學(xué)《建筑安裝工程概預(yù)算》2023-2024學(xué)年第二學(xué)期期末試卷
- 供應(yīng)鏈可持續(xù)性:環(huán)境與社會(huì)風(fēng)險(xiǎn)管理
- 有機(jī)蔬菜種植盒市場調(diào)查報(bào)告
- 許昌垂直車庫施工方案
- 2025年黃金投資分析報(bào)告:全球流動(dòng)與價(jià)格波動(dòng)中的關(guān)鍵信號(hào)
- 超長結(jié)構(gòu)廠房施工方案
- 肺結(jié)核病人的心理護(hù)理
- 2025年開封文化藝術(shù)職業(yè)學(xué)院單招職業(yè)技能測試題庫含答案
- 2025年遼寧冶金職業(yè)技術(shù)學(xué)院單招職業(yè)適應(yīng)性測試題庫有完整答案
- 2025年安徽揚(yáng)子職業(yè)技術(shù)學(xué)院單招職業(yè)適應(yīng)性測試題庫(各地真題)
- 煙草職業(yè)鑒定三級(jí)技能考點(diǎn)
- 創(chuàng)新創(chuàng)業(yè)項(xiàng)目計(jì)劃書撰寫
- 2024年上海市楊浦區(qū)復(fù)旦大學(xué)附中自主招生數(shù)學(xué)試卷
- 《汽車底盤構(gòu)造與維修》專業(yè)課程標(biāo)準(zhǔn)
- 2024年江西應(yīng)用工程職業(yè)學(xué)院單招職業(yè)技能測試題庫標(biāo)準(zhǔn)卷
- 2023年初中畢業(yè)生信息技術(shù)中考知識(shí)點(diǎn)詳解
- 做賬實(shí)操-建筑施工企業(yè)的收入確認(rèn)方法
評(píng)論
0/150
提交評(píng)論