编译原理词法分析器c

编译原理词法分析器c

ID:43641993

大小:195.70 KB

页数:19页

时间:2019-10-11

编译原理词法分析器c_第1页
编译原理词法分析器c_第2页
编译原理词法分析器c_第3页
编译原理词法分析器c_第4页
编译原理词法分析器c_第5页
资源描述:

《编译原理词法分析器c》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、编译原理词法分析器C++源程序#include#include#include#include#include#include#include/*头文件*/voidinit();char*DchangeB(char*buf);intsearch(char*buf,inttype,intcommand);voidintdeal(char*buffer);voi

2、dchardeal(char*buffer);voiderrordeal(charerror,intlineno);voidscanner();voidinit(){cha厂key卜r「autoTbreakTcaseTcharTconstTcontinueTdefaultTdoTdouble”,”elseTenumTextemTfloatTforTgotoTifTintTlongTregiste广,"return","shorr,"signed*',"sizeof","static","struct

3、","switch","typedef",“unionTunsignedTvoidTvolatileTwhile”};/*C语言所有关键字/=,+fstreamoutfile;inti,j;char*c;outfile.open(Mkey.txr,ios::out);for(i=0;i<32;i++)outfile«key[i]«endl;outfile.close();outfile.open("Limit.txt",ios::out);for(j=0;jv38;j++)outfile«limit

4、[j]«endl;c=,,n;outfile«c;outfile.close();outfile.open(,,bsf.txt,,,ios::out);outfile.close();outfile.open(ncs.txt,ios::out);outfile.close();outfile.open(Moutput.txrjos::out);outfile.close();}char*DchangeB(char*buf){int怕mp[20];char*binary;intvalue=0,i=0

5、,j;for(i=0;buf[i]!='H,,,n;i++)value=value*10+(buf[i]-48);广将字符转化为十进制数"/if(value==0){binary=newchar[2];binary[O]=,mO,m;binary[1]=,,,,,u,;return(binary);}i=0;while(value!=O){temp[i++]=value%2;value/=2;}temp[i]=',n,H,;binary=newchar[i+1];for(j=0;j<=i

6、-1;j++)binary[j]=(char)(temp[i-j-1]+48);binary[i]=m,,,M;retum(binary);广十进制转化为二进制碎/intsearch(char*buf,inttype)ntcommand){intnumber=0;fstreamoutfile;charch;chartemp[30];inti=0;switch(type){case1:outfile.open(”key.txt「ios::in);break;case2:outfile.open(,

7、,bsf.txt,ios::in);break;case3:outfile.open(Mcs.txtM,ios::in);break;case4:outfile.open(f,limit.txt,,,ios::in);break;}outfile.get(ch);while(ch!=EOF){while(ch!=m,,m){temp[i++]=ch;outfile.get(ch);}temp[i]严0””;i=0;number++;if(strcmp(temp,buf)==O){outfile

8、.close();returnnumber;广若找到,返回在相应表中的序号"/}elseoutfile.get(ch);}〃结束外层while循坏if(command==1){outfile.close();return0;广找不到,当只需查表,返回0,否则还需造衣*/}switch(type){case1:outfile.open(Mkey.txtH,ios::in);break;case2:outfile.open(,,bsf.txt,,Jos::in);brea

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。