![從正規(guī)文法構(gòu)造有窮狀態(tài)自動機_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/7/0a75b544-4fbe-4a06-91c8-3742f4d38df9/0a75b544-4fbe-4a06-91c8-3742f4d38df91.gif)
![從正規(guī)文法構(gòu)造有窮狀態(tài)自動機_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/7/0a75b544-4fbe-4a06-91c8-3742f4d38df9/0a75b544-4fbe-4a06-91c8-3742f4d38df92.gif)
![從正規(guī)文法構(gòu)造有窮狀態(tài)自動機_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/7/0a75b544-4fbe-4a06-91c8-3742f4d38df9/0a75b544-4fbe-4a06-91c8-3742f4d38df93.gif)
![從正規(guī)文法構(gòu)造有窮狀態(tài)自動機_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/7/0a75b544-4fbe-4a06-91c8-3742f4d38df9/0a75b544-4fbe-4a06-91c8-3742f4d38df94.gif)
![從正規(guī)文法構(gòu)造有窮狀態(tài)自動機_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/7/0a75b544-4fbe-4a06-91c8-3742f4d38df9/0a75b544-4fbe-4a06-91c8-3742f4d38df95.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、 特至I 學(xué)誠H 課程名稱:從正規(guī)文法構(gòu)造有夯狀態(tài)自動機 年級/專業(yè)/班:11級計算機類(二)班 姓名:徐勇兵 E01114278 從正規(guī)文法構(gòu)造有窮狀態(tài)自動機 輸入:任意的正規(guī)文法 輸由:相應(yīng)的有窮狀態(tài)自動機 要求:識別有窮狀態(tài)自動機是確定的還是 非確定的,生成相應(yīng)的五元組形式。 說明:應(yīng)檢查輸入的是否正規(guī)文法。 實驗截圖: 測試一:修結(jié)符輸出如下;如非終給荷輸出如下:5,5,A,B,A,B,產(chǎn)生式輸出如下:3 3- -akSakS- -hBShBS- -ee A A- -山-汕4B4B- -a5a5 EE是正規(guī)式狀態(tài)表輸出如下;*A,A,比“字母表輸出如下;工 6轉(zhuǎn)換函數(shù)輸出如下:3 3a
2、 aASUBSASUBSe eZkZkaBaBA AkABaSkABaSb btotoA AB*ZB*Z初態(tài)是S S終態(tài)是工是DFADFA 測試二: t terfninatea?lstLJavaAfpiicationjvrsrogrerfninatea?lstLJavaAfpiicationjvrsrograjwajwr ri iJsJs jav&jav& jrjr然結(jié)符輸出2 2口木:a,a,6 6 非終結(jié)符輸出如下;S,AS,Af fB,產(chǎn)生式輸出如下: 5 5- -alal S S- -bDbD3 3- -yeye k k- -bAbAB BaSaSB B- -ADADA
3、 AB B- -ytyt 方一AMAM乩4 4不是正規(guī)式程序結(jié)束 * 測試三: AaB B B- -?aS?aS E E- -bibi BeBe S S- -aBaB 是正規(guī)式 狀態(tài)表輸出如下:二,%B勺字母裝輸出如下:R,匕,轉(zhuǎn)換函數(shù)輸出如下 5 5日國 SEESEE S Se e2 2 AaEAaE 亞A A EaEaS S EbAEbA BeBe2 2 S Sa aS S 初態(tài)是S S: 終態(tài)是工 不是NF0NF0 importjava.util.Vector; importjavax.swing.JOptionPane; classTools publicVectorprotectio
4、n(Vectorvs) Vectornewvector=newVector(); for(inti=0;ivs.size();i+) newvector.add(vs.get(i); returnnewvector; doubleprotection(VectorVector vs)( VectorVectornewvector=newVectorVector(); for(inti=0;ivs.size();i+) Vectorproduce=(Vector)vs.get(i); Vectortemp=newVector(); for(intj=0;jproduce.size();j+) t
5、emp.add(String)produce.get(j); /forj newvector.add(temp); /fori returnnewvector; publicVectoraddElements(Vectorvs,Vectortemp) for(inti=0;itemp.size();i+) if(!vs.contains(temp.get(i) vs.add(temp.get(i); /for returnvs; /publicVectoraddElements(Vector vs,Vectortemp)/classtoolsclassElements Vectorend=ne
6、wVector();/表示終結(jié)符 Vectornoend=newVector();/表示非終結(jié)符 VectorVectorproduce=newVectorVector();/產(chǎn)生式 publicVectorVector publicvoidsetend()/終結(jié)符元素添加 while(true) Strings=JOptionPane.showInputDialog(null,請輸入終結(jié)符); if(s=null)return;/ifend.add(s);/while/publicvoidaddend()/元素添加 publicvoidsetnoend()/非終結(jié)符元素添加 while(tr
7、ue) Strings=JOptionPane.showInputDialog(null,非請輸入終結(jié)符); if(s=null)return;/ifnoend.add(s); /while /publicvoidaddnoend()/ publicvoidsetproduce() while(true) Strings=JOptionPane.showInputDialog(null,請輸入產(chǎn)生式,-隔開); if(s=null) return; Vectortemp=newVector(); temp.add(s.split(-)0); temp.add(s.split(-)1); pro
8、duce.add(temp); /while /publicvoidaddproduce() publicVectorgetend() returnend; publicVectorgetnoend() returnnoend; publicVectorVectorgetproduce() duce; publicvoidrun() /*TEST*/ end.add(a); end.add(b); noend.add(S); noend.add(A); noend.add(B); Vectortemp=newVector(); temp.add(S); temp.a
9、dd(aA); produce.add(temp); /*/ Vectortemp1=newVector(); temp1.add(S); temp1.add(bB); produce.add(temp1); /*/ Vectortemp2=newVector(); temp2.add(S); temp2.add(e); produce.add(temp2); /*/ Vectortemp3=newVector(); temp3.add(A); temp3.add(aB); produce.add(temp3); /*/ Vectortemp4=newVector(); temp4.add(A
10、); temp4.add(bA); produce.add(temp4); /*/ Vectortemp5=newVector(); temp5.add(B); temp5.add(aS); produce.add(temp5); /*/ Vectortemp6=newVector(); temp6.add(B); temp6.add(bA); produce.add(temp6); /*/ Vectortemp7=newVector(); temp7.add(B); temp7.add(e); produce.add(temp7); /*/ Vectortemp8=newVector();
11、temp8.add(S); temp8.add(aB); produce.add(temp8); /*Vectortemp9=newVector(); temp9.add(S); temp9.add(aAA); produce.add(temp9);*/ /System.out.println(produce.size()=+produce.size(); /*TEST*/ /this.setend(); /this.setnoend(); /this.setproduce(); publicbooleanIscontainend(Strings)/正則表達(dá)式判斷s1是否在END的閉包里面 正
12、則忘了怎么寫了 intlength=s.length(); for(inti=0;ilength;i+) ( Stringa=+s.charAt(i); if(end.contains(a) continue; elsereturnfalse; /for returntrue; /publicbooleanisRGPcontain(Strings) publicbooleanIsNoENd(Strings) Stringss=+s.charAt(0); if(!Iscontainend(ss)/如果不含有終結(jié)符,則為非終結(jié)符 returntrue; returnfalse; /publicbo
13、olean publicvoidshow() System.out.print(終結(jié)符輸出如下:); for(inti=0;iend.size();i+) System.out.print(String)end.get(i)+,); System.out.println(); System.out.print(非終結(jié)符輸出如下:); for(inti=0;inoend.size();i+) System.out.print(String)noend.get(i)+,); System.out.println(); System.out.print(產(chǎn)生式輸出如下:); for(inti=0;i
14、produce.size();i+) System.out.println(); Vectortemp=(Vector)produce.get(i); System.out.print(String)temp.get(0)+-+(String)temp.get(1); System.out.println(); classElementspublicclassTest Elementselements; Toolstools=newTools(); Vectorend=newVector(); Vectornoend=newVector(); VectorinputTable=newVecto
15、r();/表示輸入符號的集合即又 窮字母表 VectorstatusTable=newVector();/狀態(tài)表 VectorVectorproduce=newVectorVector();/產(chǎn)生式 表示終結(jié)符 表示非終結(jié)符 VectorVectornewproduce=newVectorVector();/轉(zhuǎn)換 函數(shù) Stringstart=S;/初態(tài) Stringlast=Z;/終態(tài) publicvoidfirststep() if(elements.Iscontainend(aA)=true) System.out.println(yes); for(inti=0;iproduce.si
16、ze();i+) Vectortemp=produce.get(i); Stringleft=temp.get(0); Stringright=temp.get(1); if(right.length()!=1)/S-aA形式 Stringone=+right.charAt(0); Stringtwo=+right.charAt(1); Vectortemp1=newVector(); temp1.add(left); temp1.add(one); temp1.add(two); newproduce.add(templ); /if else/S-a形式 Stringone=+right.c
17、harAt(0); Vectortemp1=newVector(); temp1.add(left); temp1.add(one); temp1.add(last); newproduce.add(temp1); publicbooleaniszhenggui() for(inti=0;iproduce.size();i+) Vectortemp=produce.get(i); Stringleft=temp.get(0); Stringright=temp.get(1); if(right.length()2) returnfalse; if(right.length()=1) if(el
18、ements.IsNoENd(right)=false)/S-A不滿足 returnfalse; if(right.length()=2) Stringone=+right.charAt(0); Stringtwo=+right.charAt(1); if(elements.Iscontainend(one)=false) returnfalse; if(elements.IsNoENd(two)=false) returnfalse; ) ) returntrue; ) publicvoidFA()構(gòu)造自動機 ) publicvoidsetstatusTable()/狀態(tài)表 for(inti
19、=0;inoend.size();i+) statusTable.add(noend.get(i); )statusTable.add(last); publicvoidsetinputTable()/狀態(tài)表 for(inti=0;iend.size();i+) inputTable.add(end.get(i); publicvoidshow() System.out.print(狀態(tài)表輸出如下:); for(inti=0;istatusTable.size();i+) System.out.print(String)statusTable.get(i)+,); System.out.pri
20、ntln(); System.out.print(字母表輸出如下:); for(inti=0;iinputTable.size();i+) System.out.print(String)inputTable.get(i)+,); System.out.println(); System.out.print(轉(zhuǎn)換函數(shù)輸出如下:); for(inti=0;inewproduce.size();i+) System.out.println(); Vectortemp=(Vector)newproduce.get(i); System.out.print(String)temp.get(0)+(St
21、ring)temp.get(1)+ +(String)temp.get(2); System.out.println(); System.out.println(初態(tài)是+start); System.out.println(終態(tài)是+last); ) publicbooleanjudge() booleanflag=true; VectorVectorvs=newVectorVector(); /Vectorvv=newVector(); for(inti=0;inewproduce.size();i+) Vectortemp=newproduce.get(i); Stringleft=temp.get(0); Stringmidle=temp.get(1); if(vs.isEmpty()如果是第一次放入數(shù)據(jù) Vectortemp2=newVector(); temp2.add(left); temp2.add(midle);
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 保安人員技術(shù)素養(yǎng)提升的路徑計劃
- 公共服務(wù)行業(yè)的品牌工作計劃
- 苗圃未來希望助力孩子成長計劃
- 加強跨國經(jīng)營管理提升全球競爭力計劃
- 弘揚學(xué)生尊重勞動的精神計劃
- 2025年地理信息大數(shù)據(jù)合作協(xié)議書
- 2025年中國橡膠行業(yè)市場運行態(tài)勢、產(chǎn)業(yè)鏈全景及發(fā)展趨勢報告
- 七年級下冊《立方根》課件與練習(xí)
- 利用大數(shù)據(jù)分析預(yù)測用戶需求變化
- 2025年路面清潔裝備項目建議書
- 2022版義務(wù)教育(生物學(xué))課程標(biāo)準(zhǔn)(附課標(biāo)解讀)
- 醫(yī)院放射診療中的輻射防護(hù)常識學(xué)習(xí)培訓(xùn)
- 《中國山水畫技法》課件
- 如何提升小學(xué)教學(xué)質(zhì)量
- 陜西省西安市2023-2024學(xué)年六年級上學(xué)期期末數(shù)學(xué)試卷(A卷)
- 變電站模塊化建設(shè)2.0版技術(shù)導(dǎo)則
- 無人機飛行表演合同
- 廣州市2023年中考:《道德法治》考試真題與參考答案
- 爺爺?shù)臓敔斈睦飦恚喝祟惼鹪吹难莼^程
- 公會掛靠協(xié)議
- 欒川光伏扶貧發(fā)電項目部qc成果
評論
0/150
提交評論