用狀態(tài)機實現(xiàn)去除注釋_第1頁
用狀態(tài)機實現(xiàn)去除注釋_第2頁
用狀態(tài)機實現(xiàn)去除注釋_第3頁
用狀態(tài)機實現(xiàn)去除注釋_第4頁
用狀態(tài)機實現(xiàn)去除注釋_第5頁
全文預覽已結(jié)束

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、1/*/* 2* ÓÃ״̬»úʵÏÖ¶Ô´úÂëÖÐ×¢Ê͵ÄÇå³ý. 3*/ 4 5#include <stdio.h> 6#include <string.h> 7 8#define SCREEN 910void initialize_fsm(char fsm7

2、256);1112int main()1314 int ch , temp = 0 ;15 int state = 0;16 char fsm7256;1718 FILE *pfin ;19 if (pfin = fopen("sweep-comments.txt","r") = NULL)20 21 printf("can not open the file");22 exit(0);23 2425 #ifdef SCREEN26 #define OUT stdout27 #else28 FILE *pfout;29 pfout =

3、 fopen("result.txt","w");30 #define OUT pfout31 #endif3233 initialize_fsm(fsm);3435 #pragma region FSM /*/³¢ÊÔ#pragma region¹¦ÄÜ. Visual C+ 20053637 while (ch = fgetc(pfin) != EOF)38 39 state = fsmstatech;4041 if ( state != 2 && ch

4、!='*' && temp = '/')42 fputc(temp,OUT);4344 temp = ch;4546 switch(state)47 48 /*/*0,5,6Ö´ÐÐͬһ¸ö¶¯×÷*/49 case 5:50 case 6:51 case 0:52 fputc(ch,OUT);53 break;54 case 7:55 state = 0;56 break;57 5859 if(stat

5、e != 1)60 temp=0;61 62 #pragma endregion636465void initialize_fsm(char fsm7256)6667 int lenth = sizeof(char)*256;6869 memset(fsm0,0,lenth);70 memset(fsm1,0,lenth);71 memset(fsm2,2,lenth);72 memset(fsm3,3,lenth);73 memset(fsm4,3,lenth);74 memset(fsm5,5,lenth);75 memset(fsm6,5,lenth);7677 fsm0'&qu

6、ot;' = 5;78 fsm0'/' = 1;79 fsm1'/' = 2;80 fsm1'*' = 3;81 fsm2'n' = 0;82 fsm3'*' = 4;83 fsm4'/' = 7;84 fsm5'' = 6;85 fsm5'"' = 0;8687´úÂë2 1% 2/*/* 3*ÓÃlexʵÏÖÇå³&

7、#253;´úÂë×¢ÊÍ 4*/ 5void comment(int style); 6void string_constant(); 7const int singalline =0, multiline =1; 8 9%101112%1314"/*" comment(multiline );15"/" comment(singalline);16""" string_constant();17.|n fprintf(yyout,"

8、%c",*yytext); 1819%2021int main(int argc,char *argv)2223 FILE *pfin ,*pfout;24 if (pfin = fopen (argv1,"r") =NULL)25 26 printf("can not open the filen");27 exit (1);28 29 pfout = fopen("output.txt","w");30 31 yyin = pfin;32 yyout = pfout;33 34 yylex();353

9、6 return 0;373839void string_constant()4041 int ch ;4243 fprintf(yyout,"%c",*yytext);4445 while ( (ch = input() != EOF)46 47 if (ch = '')48 49 fprintf(yyout,"%c",ch);50 ch = input();51 fprintf(yyout,"%c",ch);52 53 continue;54 5556 if (ch = '"')57 58

10、 fprintf(yyout,"%c",ch);59 break;60 61 62 fprintf(yyout,"%c",ch);63 646566void comment(int style)6768 int ch , prev=0;69 if (style = multiline)70 71 while ( (ch = input() != EOF )72 73 if (prev = '*' && ch = '/')74 return ;7576 prev = ch;77 78 79 return ;80 81 else82 83

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論