freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內容

編譯原理課程設計報告--詞法分析器-wenkub.com

2024-11-08 22:00 本頁面
   

【正文】 lllll 實現(xiàn)方法:編程語言、編程方法 系統(tǒng)總圖,各部分的實現(xiàn)原理、方法、中間結果、最后輸出 掃描器:各單詞的狀態(tài)轉換圖、轉換表 分析器:分析表 代碼設計說明:程序結構圖,文件和函數(shù)的設計說明,關鍵數(shù)據結構按文件列出主要程序代碼, 添加必要的注釋。由于此程序的實現(xiàn)相對比較復雜,且不方便調試,改進時可以把此程序的詞法分析,語法分析和執(zhí)行原代碼作為單獨的測試程序來測試,這樣也方便大家來調試。// 保存代碼()。(BEGINSYM),(CALLSYM),(IFSYM),(WHILESYM)。} : include ”“ void main(){ PL0 cp(”“,”)。l= l1。}//switch end}while(p!=0)。break。break。s[t+2]= b。case STO:s[base(,b,s)+]= s[t]。break。break。break。break。break。break。break。break。s[t]= s[t] / s[t+1]。case 4: t= t1。break。case 1: s[t]=s[t]。case OPR:switch()//operator{ case 0:// return t= b1。}} } }//condition end// 對目標代碼的解釋執(zhí)行程序void PL0::interpret(){ int err1=()。case GTR: gen(OPR,0,12)。case LSS: gen(OPR,0,10)。switch(relop){case EQL: gen(OPR,0,8)。if((sym)==())error(20)。if(sym == ODDSYM){getsym()。}test(fsys,facbegsys,23)。(RPAREN)。}gen(LIT,0,num)。break。break。test(facbegsys,fsys,24)。factor(tmp,tx,lev)。while(sym=TIMES amp。symset tmp=fsys。if(addop ==PLUS)gen(OPR,0,2)。amp。term(tmp,tx,lev)。if(sym=PLUSamp。}//statement end// 表達式處理void PL0::expression(symset fsys,int tx,int lev){ symbol addop。gen(JPC,0,cx1)。elseerror(34)。statement(temp1,tx,lev)。} else if(sym == REPEATSYM){symset temp1, temp2。elseerror(18)。condition(tmp,tx,lev)。} else if(sym ==WHILESYM){ cx1= cx。if(sym==ENDSYM)break。tmp=fsys。if(sym ==SEMICOLON||sym ==ENDSYM)getsym()。statement(tmp,tx,lev)。} } else if(sym ==BEGINSYM){ getsym()。gen(JMP,0,0)。getsym()。cx1= cx。i((symbol)i)。getsym()。else {i= position(id,tx)。elsegetsym()。expression(tmp,tx,lev)。if(sym==LPAREN){do{getsym()。if(sym!= RPAREN){error(33)。else{gen(OPR,0,16)。elsedo{getsym()。if(sym!= SEMICOLON)error(10)。}getsym()。if(sym ==IDENT){i= position(id,tx)。} // 列出目標代碼清單void PL0::listcode(int cx0)//list code generated for this block { int i。getsym()。}elseerror(32)。dx,int lev){int upscript=0,downscript=0。getsym()。} elseerror(4)。if(sym == NUMBER){enter(CONSTANT,tx,dx,lev)。if(sym=EQLamp。return i。} }//enter end// 查找標示符在名字表中的位置int PL0::position(alfa id,int tx)//find identifier id in table { int i。case PROCEDURE:table[tx].=lev。case VARIABLE:table[tx].=lev。switch(k){ case CONSTANT:if(numamax){error(31)。tx,int amp。// return symset s2。for(int i=SEMICOLON。// start adr of code table[tx0].=dx。test(tmp,declbegsys,7)。test(tmp,fsys,6)。if(sym == SEMICOLON){getsym()。elseerror(5)。if(sym ==IDENT){enter(PROCEDURE,tx,dx,lev)。}if(sym ==SEMICOLON)getsym()。if(sym == VARSYM)// 處理變量聲明 { getsym()。constdeclaration(tx,dx,lev)。if(levlevmax)error(32)。// initial code indexdx= 3。} }//test end// 分程序分析處理過程void PL0::block(int lev,int tx,symset fsys){ if(sourceEnd)return。for(it=()。cx= cx+1。}// 生成目標代碼,并送入目標程序區(qū)void PL0::gen(fct x,int y,int z){ if(cx cxmax){coutreturn。ll=strlen(line)。return。} else// end of extra stuff { sym= ssym[ch]。=39。} else if(ch == 39。=39。} else if(ch == 39。k= k+1。num= 0。if(strcmp(id,word[k])=0)i= k+1。i= 1。 39。if(sourceEnd)return。memset(a,0,al+1)。while(ch ==39。(s+errStr[n])。// code line =fopen(source,”r“)。// 行緩沖區(qū)長度ch= 39。// 初始化項開始符號集合err= 0。strcpy(mnemonic[JPC],” jpc “)。strcpy(mnemonic[STO],” sto “)。]= SEMICOLON。39。// 初始化保留字表中每一個保// 初始化一些符號對應的symbolssym[39。]= COMMA。=39。ssym[39。]= SLASH。*39。類型表ssym[39。memset(line,0,sizeof(line))。wsym[16]= WRITESYM。wsym[12]= THENSYM。wsym[8]= ODDSYM。wsym[4]= DOSYM。strcpy(word[16],”write“)。strcpy(word[12],”then“)。strcpy(word[8],”odd“)。strcpy(word[4],”do“)。// PL0構造函數(shù)PL0::PL0(char* source,char*destination){ listswitch=true,sourceEnd=false。endif : include “”// 錯誤字符串數(shù)組string PL0::errStr[]={“,”error 0001: 常數(shù)說明中“=”寫成“:=”“, ”error 0002: 常數(shù)說明中的“=”后應為數(shù)字“, ”error 0003: 常數(shù)說明中的標識符后應是“=”“, ”error 0004: const,var,procedure后應為標識符“, ”error 0005: 漏掉了‘,’或‘。void interpret()。void condition(symset fsys,int tx,int lev)。void statement(symset fsys,int tx,int lev)。void vardeclaration(intamp。int position(alfa id,int tx)。合法void block(int lev,int tx,symset fsys)。位置和出錯代碼void getsym()。// 符號表FILE* fin,*fout。// 保留字表中每一個保留字對應的symbol類型symbol ssym[100]。// error array alfa a。// code allocation index int codeNo。// last number readint cc。char ch。int val。// 類PCODE指令類型,包含三個字段:指令f、層差l和另一個操作數(shù)a/******************************************* * lit 0,a: load constant a* * opr 0,a: execute operation a* * lod l,a: load variable l,a* * sto l,a: store variable l,a* * cal l,a: call procedure a at level l* * int 0,a: increment tregister by a* * jmp 0,a: jump to a* * jpc 0,a: jump conditional to a* *******************************************/typedef struct{ alfa name。// level,cann39。// 三種標識符的類型 typedef enum {LIT,OPR,LOD,STO,CAL,INT,JMP,JPC} fct。// size of code array 類PCODE目標代碼數(shù)組長度(可容納代碼行數(shù))const int lineLength = 82。// length of identifiers 標示符的最大長度const int nmax = 14。五、相關代碼及運行結果實驗代碼; : include include include include include include ifndef WIRTH_ZYC_ define WIRTH_ZYC_ using namespace std。通過前面記錄下的jpc指令的位置,把它的跳轉位置改成當前的代碼段指針位置,否則沒遇到else,那么此時的當前代碼段分配指針的位置也是上面jpc指令的轉移位置,也是通過前面記錄下的jpc位置指令的位置,把它的跳轉到當前的代碼段指針位置。ifthenelse語句的處理:按if語句的語法,首先調用邏輯表達式處理過程處理if語句的條件,把相應的真假值放到數(shù)據棧頂。除此之外,還有出錯報告過程(Error)、代碼生成過程(Gen)、測試單詞合法性及出錯恢復過程(Test)、登錄名字表過程(Enter)、查詢名字表函數(shù)(Position)以及列出類 PCODE代碼過程(Listcode)作過語法分析的輔助過程。如果遇到不合法的字符,把SYM置成NUL。如果這個字符是字母,則繼續(xù)獲取字符或數(shù)字,最終可以拼成一個單詞,查保留字表,如果查到為保留字,則把SYM變量賦成相應的保留字類型值;如果沒有查到,則這個單詞應是一個用戶自定義的標識符(可能是變量名、常量名或是過程的名字),把SYM置為IDENT,把這個單詞存入ID變量。詞法分析子程序分析:詞法分析子程序名為GETSYM,功能是從源程序中讀出一個單詞符號(TOTAKEN),把它的信息放入全局變量 SYM、ID和NUM中,字符變量放入CH中,語法分析器需要單詞時,直接從這三個變量中獲得。四、實驗分析PL/0語言編譯程序采用以語法分析為核心、一遍掃描的編譯方法。PL/0的編譯程序和目標程序的解釋執(zhí)行程序都是用PASCAL語言書寫的,因此PL/0語言可在配備PASCAL語言的任何機
點擊復制文檔內容
規(guī)章制度相關推薦
文庫吧 www.dybbs8.com
備案圖片鄂ICP備17016276號-1