ImageVerifierCode 换一换
格式:DOCX , 页数:29 ,大小:17.96KB ,
资源ID:5672792      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5672792.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(编译原理实验1扫描器的设计与实现.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

编译原理实验1扫描器的设计与实现.docx

1、编译原理实验1扫描器的设计与实现实验1: 扫描器的设计与实现1.1.目的和要求1加深对词法分析理论的理解,培养动手实践的能力。2学会从以字符串表示的源程序中识别出具有独立意义的基本语法单位,同时指出它们的属性的方法和技术。1.2.实验环境Windows XP + WinTC1911.3.实验准备1、先将课本3.5节词法分析程序的生成认真的学习一遍,理解词法分析程序的构成过程。2、写出C语言测试程序,分析可能得到的结果。测试程序:#define pi 3.14void main double r = 2.5; double s = 0.0; s = pi*r*r; printf;预测结果:502

2、,502,1.4.实验内容及步骤1、输入已给的文本格式的扫描程序Lexical.c文件,然后编译运行,检查修改错误。2、编译成功后,提示输入C语言测试程序,用回车键查看输出的单词流,即单词符号及其属性。3、比较自己分析的结果和屏幕上的输出结果。1.5.实验小结1、得到的经验。通过本次实验,我了解了如何设计、编制并调试词法分析程序,加深了对词法分析原理的理解。同时,在编制和调试程序时要全面考虑,避免漏掉或者错误定义定界符等,造成不必要的错误。2、遇到的主要问题。忘记对空格、回车符等定界符进行设置等。3、改进方案。1char *keywords15 = void,main,if,then,brea

3、k,int,char,float,include,for,while,printf,scanf,define,double;2case 13:flag = 14;status = 1;break;case 14:flag = 15;status = 1;break;3case.:wordsj = ch;wordsj+1 = 0;flag = 514;break;case :wordsj = ;flag = 250;break;casen:flag = 251;break;4else if修改前源代码:#includestdio.h#includestdlib.h#includestring.h

4、int i,j,k,flag,number,status;/*status which is use to judge the string is keywords or not!*/char ch;char words10 = ;char program500;int Scanchar *keywords13 = void,main,if,then,break,int,char,float,include,for,while,printf,scanf;number = 0;status = 0;j = 0;ch = programi+; /* To handle the lettle spa

5、ce ands tab*/*handle letters*/if = a & ch while = a & ch wordsj+=ch;ch=programi+;i-;wordsj+ = 0;for k = 0; k if strcmp = 0switchcase 0:flag = 1;status = 1;break;case 1:flag = 2;status = 1;break;case 2:flag = 3;status = 1;break;case 3:flag = 4;status = 1;break;case 4:flag = 5;status = 1;break;case 5:

6、flag = 6;status = 1;break;case 6:flag = 7;status = 1;break;case 7:flag = 8;status = 1;break;case 8:flag = 9;status = 1;break;case 9:flag = 10;status = 1;break;case 10:flag = 11;status = 1;break;case 11:flag = 12;status = 1;break;case 12:flag = 13;status = 1;break;if flag = 100;/*handle digits*/else

7、if = 0 & ch number = 0;while = 0 & ch number = number*10+;ch= programi+;flag = 200;i-;/*opereation and edge handle*/else switch case =:if wordsj+ = ch;wordsj= 0;ch= programi+;if wordsj+ = ch;wordsj= 0;flag = 401;elsei-;flag = 402;break;case:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wo

8、rdsj = 0;flag = 403;elsei-;flag = 404;break;case:if ch = wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj= 0;flag = 405;elsei-;flag = 406;break;case!:if wordsj+ = ch;wordsj= 0;ch = programi+;if wordsj+ = ch;wordsj= 0;flag= 407;elsei-;flag = 408;break;case+:if wordsj+ = ch;wordsj = 0;ch=

9、programi+;if wordsj+ = ch;wordsj = 0;flag= 409;else if wordsj+ = ch;wordsj = 0;flag= 410;elsei-;flag= 411;break;case-:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag = 412;else ifwordsj+ = ch;wordsj = 0;flag = 413;elsei-;flag = 414;break;case*:if wordsj+ = ch;wordsj = 0;ch=

10、programi+;if wordsj+ = ch;wordsj = 0;flag = 415;elsei-;flag = 416;break;case/:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag= 417;elsei-;flag = 418;break;case;:wordsj = ch;wordsj+1 = 0;flag = 501;break;case:wordsj = ch;wordsj+1 = 0;flag = 503;break;case:wordsj = ch;wordsj+1

11、 = 0;flag = 504;break;case:wordsj = ch;wordsj+1 = 0;flag = 505;break;case:wordsj = ch;wordsj+1 = 0;flag= 506;break;case:wordsj = ch;wordsj+1 = 0;flag = 507;break;case:wordsj = ch;wordsj+1 = 0;flag = 508;break;case:wordsj = ch;wordsj+1 = 0;flag = 509;break;case%:if wordsj+ = ch;wordsj = 0;ch = progra

12、mi+;if wordsj+ = ch;wordsj = 0;flag= 510;elsei-;flag = 511;break;case,:wordsj = ch;wordsj+1 = 0;flag = 512;break;case#:wordsj = ch;wordsj+1 = 0;flag = 513;break;case:wordsj = #;flag = 0;break;default:flag = -1;break;return flag;maini=0;printf;doch = getchar;programi+ = ch;while;i = 0;doflag = Scan;i

13、f printf,flag,number;else if printf,flag;elseprintf,flag,words;while ;system;修改后源代码:#includestdio.h#includestdlib.h#includestring.hint i,j,k,flag,number,status;/*status which is use to judge the string is keywords or not!*/char ch;char words10 = ;char program500;int Scanchar *keywords15 = void,main,

14、if,then,break,int,char,float,include,for,while,printf,scanf,define,double;number = 0;status = 0;j = 0;ch = programi+; /* To handle the lettle space ands tab*/*handle letters*/if = a & ch while = a & ch wordsj+=ch;ch=programi+;i-;wordsj+ = 0;for k = 0; k if strcmp = 0switchcase 0:flag = 1;status = 1;

15、break;case 1:flag = 2;status = 1;break;case 2:flag = 3;status = 1;break;case 3:flag = 4;status = 1;break;case 4:flag = 5;status = 1;break;case 5:flag = 6;status = 1;break;case 6:flag = 7;status = 1;break;case 7:flag = 8;status = 1;break;case 8:flag = 9;status = 1;break;case 9:flag = 10;status = 1;br

16、eak;case 10:flag = 11;status = 1;break;case 11:flag = 12;status = 1;break;case 12:flag = 13;status = 1;break;case 13:flag = 14;status = 1;break;case 14:flag = 15;status = 1;break;if flag = 100;/*handle digits*/else if = 0 & ch number = 0;while = 0 & ch number = number*10+;ch= programi+;flag = 200;i-

17、;/*opereation and edge handle*/else switch case =:if wordsj+ = ch;wordsj= 0;ch= programi+;if wordsj+ = ch;wordsj= 0;flag = 401;elsei-;flag = 402;break;case:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag = 403;elsei-;flag = 404;break;case:if ch = wordsj+ = ch;wordsj = 0;ch=

18、programi+;if wordsj+ = ch;wordsj= 0;flag = 405;elsei-;flag = 406;break;case!:if wordsj+ = ch;wordsj= 0;ch = programi+;if wordsj+ = ch;wordsj= 0;flag= 407;elsei-;flag = 408;break;case+:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag= 409;else if wordsj+ = ch;wordsj = 0;flag=

19、410;elsei-;flag= 411;break;case-:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag = 412;else ifwordsj+ = ch;wordsj = 0;flag = 413;elsei-;flag = 414;break;case*:if wordsj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag = 415;elsei-;flag = 416;break;case/:if word

20、sj+ = ch;wordsj = 0;ch= programi+;if wordsj+ = ch;wordsj = 0;flag= 417;elsei-;flag = 418;break;case;:wordsj = ch;wordsj+1 = 0;flag = 501;break;case:wordsj = ch;wordsj+1 = 0;flag = 503;break;case:wordsj = ch;wordsj+1 = 0;flag = 504;break;case:wordsj = ch;wordsj+1 = 0;flag = 505;break;case:wordsj = ch;wordsj+1 = 0;flag= 506;break;case:wordsj = ch;wordsj+1 = 0;flag = 507;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1