编译——词法分析

编译——词法分析

ID:44645004

大小:75.50 KB

页数:6页

时间:2019-10-24

编译——词法分析_第1页
编译——词法分析_第2页
编译——词法分析_第3页
编译——词法分析_第4页
编译——词法分析_第5页
资源描述:

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

1、#include#include#include#includetypedefstructWord/*Word*//*thenumberoftheWord*//*ifletter*inoLA'~Zthenitisaletter*/{charchWd[20];intnN;structWord*next;JWord;intIsAlphaLetter(charcletter){if(cletter>=,A,&&cletterv=Z)return1;if(clcttc

2、r>='a'&&cletter<='z')return1;return0;intIsnumbcr(charenum){if(cnum>='0'&&cnum<='9')return1;return0;intIssign(charesg)/*AccordingtotheASCIItable*/{if(csg>='!*&&csg<=,/1)return1;if(csg>=':'&&csg<='@')return1;if(csg>=T&&csg<=,J)return1;if(csg>='{'&&csgv='~')return1;return0

3、;/*Printallthewords/*palHeadisthe/*pnumHeadis/*psghcadisthevoidPrint(Word*palHead.Word*pnumHead,Word*psgHead)recognizedinthequeueoflpWord*/{headofwords*/intnPos=0;theheadofnumbers*/headofsigns*/printf(nlnthesentense,words:n);while(palHead!=0){printf("NO.%d:%su,nPos+

4、1,palHead->chWd);palHead=palHead->next;nPos++;}nPos=0;printf(nlnthesentense,numbers:M);while(pnumHead!=0){printf("NO.%d:%s",nPos+1,pnumHcad->chWd);pnumHead=pnumHead->next;nPos++;}nPos=0;printf(ulnthesentense,signs:H);while(psgHead!=0){printf("NO.%d:%sn,nPos+l,ps

5、gHead->chWd);psgHcad=psgHcad->ncxt;nPos++;voidGetWords(charlpString[],Word*palHead,Word*pnumHead,Word*psgHead)/*Torecognizethewordsinlpstringtostoreintolpword*/{/*andstorewordstopalhead,numberstopnumHead,signstopsgHead*/WordwdCurrcnt;/*IpStringistostorethesentencetobere

6、congnisewords,numbers,signsfrom*/Word*p=0;intintintintnCharPos=0;nStringLcn;nFlg=0;nl=0;if(lpString[()l==、()'){printfC'NullString!");return;for(nl=O;;nl++)/*togetthelengthandendoflpstring*/if(lpString[nIl==A0,){nStringLen=nl;break;}nFlg=0;theendoftheword*//*'nFlg'istoma

7、rkwhilc(nCharPos

8、*Haverecognisedanewp=(Word*)malloc(sizcof(Word));/*andthenmallocaunittostoreit*/printf(HMemoryLack!'*);exit(-l

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

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

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