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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

算术表达式语法检查 实验报告.docx

1、算术表达式语法检查 实验报告中南民族大学计算机科学学院本科课程设计任 务 书设计名称: 算术表达式语法检查 指导教师: 下达时间: 2015-5-8学生姓名: 学 号: 专 业: 一、 课程设计的基本要求根据所学知识,编写指定题目的C+语言程序,并规范地完成课程设计报告。通过课程设计,加深对C+面向对象程序设计课程所学知识的理解,熟练掌握和巩固C+语言的基本知识和语法规范,掌握C+语言的基础知识,理解面向对象系统的封装性、继承性和多态性;熟练使用C语言中的函数、数组、指针、链表和字符串等基本知识;掌握类的定义、标准String类和向量; 理解掌握友元函数和重载操作符,动态数组;理解掌握继承和多

2、态性;掌握模版的使用;能够进行程序调试过程中的异常处理;进一步掌握利用C+进行类的定义和操作方法;进一步掌握类的继承和派生方法;进一步理解虚函数和多态;综合利用上述知识,学习设计并编写面向对象的C+简单应用程序;培养解决复杂任务功能分解方法(自顶向下逐步求精、模块化设计、信息隐藏等)。学会编制结构清晰、风格良好、数据结构适当的C+语言程序,从而具备利用计算机编程分析解决综合性实际问题的初步能力。具体要求如下:1、 采取模块化方式进行程序设计,要求程序的功能设计、数据结构设计及整体结构设计合理。学生也可根据自己对题目的理解增加新的功能模块(视情况可另外加分)。2、 系统以菜单界面方式(至少采用文

3、本菜单界面,如能采用图形菜单界面更好)工作,运行界面友好,演示程序以用户和计算机的对话方式进行。3、 程序算法说明清晰,理论分析与计算正确,运行情况良好,实验测试数据无误,容错性强(能对错误输入进行判断控制)。4、 编程风格良好(包括缩进、空行、适当注释、变量名和函数名见名知意,程序容易阅读等);5、 写出规范的课程设计报告,具体要求见相关说明文档。二、 课程设计的主要内容【问题描述】算术表达式语法检查。【功能要求】(1)键盘读入一个四则运算算术表达式,对其进行语法检查;(2)算术表达式允许嵌套,如果出错,指出出错位置;(3)不需要计算结果;(4)尽量不使用栈。程序:(其余的你们自己写)voi

4、d main() /主函数 int len; int f=1; coutendl请输入一个算术表达式(请在一行内完成输入且每个项的长度不大于10):endl; gets(str); len = strlen(str); strlen = ; coutendl; system(pause); coutendl; cout*词法分析开始*endl; f = cifa_main(); if ( f = 0 ) return; coutendl; system(pause); coutendl; cout*语法分析开始*endl; f = yufa_main(); if (f= 0) return;

5、coutendl; system(pause); cout (E) | 标识符 | 无符号整数 if (strcmp(cifa_p-word,() = 0 ) ) advance(); strcpy(F_name,cifa_p-word); strcpy(E_name,F_name); E1(); if (strcmp(cifa_p-word,) = 0 ) ) advance(); strcpy(F_name,E_name); return (1); else coutERRORtype = 1 | cifa_p-type = 2) strcpy(F_name,cifa_p-word); a

6、dvance(); return (1); else return 0;int T1() /T - F*T | F/T | F yuyi *p = new yuyi; F1(); strcpy(p-op1,F_name); if (strcmp(cifa_p-word,*) = 0) advance(); T1(); p-next =NULL; p-op = *; strcpy(p-op2,T_name); T_name0 = t; T_name1 = +count; T_name2 = 0; strcpy(p-result,T_name); yuyi_add(p); return(1); e

7、lse if (strcmp(cifa_p-word,/) = 0) advance(); T1(); p-next =NULL; p-op = /; strcpy(p-op2,T_name); T_name0 = t; T_name1 = +count; T_name2 = 0; strcpy(p-result,T_name); yuyi_add(p); return(1); else strcpy(T_name,F_name); return(1); int E1() /E - T+E | T-E | T yuyi *p = new yuyi; T1(); strcpy(p-op1,T_n

8、ame); if (strcmp(cifa_p-word,+) = 0) advance(); E1(); p-next =NULL; p-op = +; strcpy(p-op2,E_name); E_name0 = t; E_name1 = +count; E_name2 = 0; strcpy(p-result,E_name); yuyi_add(p); return (1); else if (strcmp(cifa_p-word,-) = 0) advance(); E1(); p-next =NULL; p-op = -; strcpy(p-op2,E_name); E_name0

9、 = t; E_name1 = +count; E_name2 = 0; strcpy(p-result,E_name); yuyi_add(p); return(1); else strcpy(E_name,T_name); return(1); int yufa_main() /语法分析主程序 int n; cifa *p = new cifa; strcpy(p - word ,#); /对词法分析产生的结果链表进行处理 p - type =-1; p - next = NULL; cifa_add(p); cifa_p = cifa_head; coutnext); cout的递归分析

10、过程如下:endl; coutendl-endl; coutt步骤tt产生式endl; advance(); n = E(); if (n = 0) couttftt输入串不是该文法的一个句子!endl; coutendl-语法分析结束-endl; return (0); else if (n = 1) couttftt输入串是该文法的一个句子!endl; coutendl-语法分析结束-next = p ; yuyi_end = p; return yuyi_head;void yuyi_sys_disp() /输出四元式链表 yuyi *p; p = yuyi_head-next; whi

11、le(p!=NULL) cout(top,top1,top2,tresultt)next; cout (E) | 标识符 | 无符号整数 子函数 int m; if (strcmp(cifa_p-word,() = 0 ) ) couttf+tt (E)word,) = 0 ) ) advance(); return (1); else coutERRORtype = 1 | cifa_p-type = 2) /数字或是标识符 couttf+tt 标识符|无符号整数 *FS | /FS | 子函数 int t,g; if (strcmp(cifa_p-word,*) = 0) couttf+t

12、t *FSword,/) = 0) couttf+tt /FSword,+) = 0 |(strcmp(cifa_p-word,-) = 0)|(strcmp(cifa_p-word,#) = 0)|(strcmp(cifa_p-word,) = 0) couttf+tt FS 子函数 int t,g; couttf+tt FSword,+) = 0) couttf+tt +TGword,-) = 0) couttf+tt -TGword,) = 0 | strcmp(cifa_p-word,#) = 0) couttf+tt +|-TG 子函数 int t,g; if (strcmp(cif

13、a_p-word,+) = 0)| (strcmp(cifa_p-word,-) = 0) advance(); couttf+tt +|-TGendl; t = T(); if (t = 0) return (0); g = G(); if (g = 0) return (0); else return (1);void yufa_zfc_disp(cifa *p) /输出字符串 while(p!=NULL) coutword ; p = p-next; / cout next;int test(void) /识别相关符号 char temp3; int i=0; int type; swi

14、tch (ch) case ; : /识别 ; tempi+ = ch; GetChar(); if (ch = ) tempi+ = ; tempi = 0; type = 4; break; case + : /识别 + tempi+ = ch; GetChar(); if (ch = ) tempi+ = ; tempi = 0; type = 3; break; case - : /识别 - tempi+ = ch; GetChar(); if (ch = ) tempi+ = ; tempi = 0; type = 3; break; case * : /识别 * tempi+ =

15、ch; GetChar(); if (ch = ) tempi+ = ; tempi = 0; type = 3; break; case / : /识别 / tempi+ = ch; GetChar(); if (ch = ) tempi+ = ; tempi = 0; type = 3; break; case ( : /识别 ( tempi+ = ch; GetChar(); if (ch = ) tempi+ = ; tempi = 0; type = 4; break; case ) : / 识别) tempi+ = ch; GetChar(); if (ch = ) tempi+

16、= ; tempi = 0; type = 4; break; default : coutch; cout无法识别,出错! next = NULL; p - type = type; strcpy(p-word,temp); cifa_add(p); return (1); int cifa_main() /词法分析主函数 int f; cifa_head = new cifa; cifa_head - type = -1; cifa_head - next = NULL; cifa_end = cifa_head; cout单词种类定义如下:endlendl; cout标识符的种类编码 1

17、 :endlendl; cout常数的种类编码 2 :endlendl; cout运算的种类编码 3 :+ ,- ,* ,/ endlendl; cout界限符的种类编码 4 : (,),;endl; GetChar(); notock(); cout-endl词法分析结果如下:endl; while ( nn = a & ch = A & ch = 0 & ch = 9) f=number(); /数字串 else f=test();/其他符号 if (f = 0) return (0); cifa_disp(cifa_head); coutendl-词法分析结束-endl; return

18、(1);int number(void) /识别数字 int type=2; int i=0; char temp10; while(0= ch & ch = 9) tempi = ch; i+; GetChar(); tempi=0; if (ch = ) notock(); else if (ch != & ch != + & ch != - & ch != ; & ch != * & ch != / & ch != (& ch != ) couttemp接错误后缀,出错 next = NULL; p - type = type; strcpy(p-word,temp); cifa_add

19、(p); return (1);int alph(void) /识别标识符 int i=0; char temp10; int type = 1; tempi = ch; i+; GetChar(); while (ch = a & ch = A & ch = 0 & ch = 9) tempi = ch; i+; GetChar(); tempi = 0; if (ch = ) notock(); else if (ch != & ch != + & ch != - & ch != ; & ch != * & ch != / & ch != (& ch != ) couttemp接错误后缀,出错 next = NULL; p - type = type; strcpy(p-word,temp); cifa_add(p); return (1);cifa *cifa_add(cifa *p) /在分析结果列表尾添加一个新

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

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