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

上传人:第*** 文档编号:34241902 上传时间:2018-02-22 格式:DOC 页数:21 大小:59.50KB
返回 下载 相关 举报
算术表达式语法检查_实验报告_第1页
第1页 / 共21页
算术表达式语法检查_实验报告_第2页
第2页 / 共21页
算术表达式语法检查_实验报告_第3页
第3页 / 共21页
算术表达式语法检查_实验报告_第4页
第4页 / 共21页
算术表达式语法检查_实验报告_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《算术表达式语法检查_实验报告》由会员分享,可在线阅读,更多相关《算术表达式语法检查_实验报告(21页珍藏版)》请在金锄头文库上搜索。

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

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

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

4、的你们自己写)void main() /主函数 int len;int f=1;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 couttype = 1 | cifa_p-type = 2)strcpy(F_name,cifa_p-word);

5、advance();return (1);- 4 -else return 0;int T1() /T - F*T | F/T | Fyuyi *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);else if (st

6、rcmp(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;- 5 -strcpy(p-result,T_name);yuyi_add(p);return(1);elsestrcpy(T_name,F_name);return(1);int E1() /E - T+E | T-E | Tyuyi *p = new yuyi;T1(); strcpy(p-op1,T_name);if (strcmp(cifa_

7、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) - 6 -advance();E1();p-next =NULL;p-op = -;strcpy(p-op2,E_name);E_name0 = t;E_name1 = +count;E_name2 = 0

8、;strcpy(p-result,E_name);yuyi_add(p);return(1);elsestrcpy(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);coutnext = p ;yuyi_end = p;return yuyi_head;void yuyi_sys_d

9、isp() /输出四元式链表 yuyi *p;p = yuyi_head-next;while(p!=NULL) coutopop1op2resultnext;- 8 -cout (E) | 标识符 | 无符号整数 子函数int m;if (strcmp(cifa_p-word,() = 0 ) ) cout (E)word,) = 0 ) ) advance();return (1);else couttype = 1 | cifa_p-type = 2) /数字或是标识符cout 标识符|无符号整数 *FS | /FS | 子函数int t,g;if (strcmp(cifa_p-word

10、,*) = 0) cout *FSword,/) = 0) cout /FSword,+) = 0 |(strcmp(cifa_p-word,-) = 0)|(strcmp(cifa_p-word,#) = 0)|(strcmp(cifa_p-word,) = 0) cout FS 子函数int t,g;cout FSword,+) = 0) cout +TGword,-) = 0) cout -TGword,) = 0 | strcmp(cifa_p-word,#) = 0) cout +|-TG 子函数int t,g;if (strcmp(cifa_p-word,+) = 0)| (str

11、cmp(cifa_p-word,-) = 0) advance();cout +|-TGword ;p = p-next;/ cout next;int test(void) /识别相关符号 char temp3;int i=0;int type;switch (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;

12、case - : /识别 - 13 -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+ = ch;GetChar();if (ch = ) tempi+ = ;tempi = 0;type = 3;break;case ( : /识别 (tempi+ = ch; - 14 -GetChar();if (c

13、h = ) tempi+ = ;tempi = 0;type = 4;break;case ) : / 识别)tempi+ = ch; GetChar();if (ch = ) tempi+ = ; tempi = 0;type = 4;break; default : cout next = NULL;p - type = type;strcpy(p-word,temp);- 15 -cifa_add(p); return (1); int cifa_main() /词法分析主函数int f;cifa_head = new cifa;cifa_head - type = -1;cifa_he

14、ad - next = NULL;cifa_end = cifa_head;cout= a & ch = A & ch = 0 /数字串else f=test();/其他符号if (f = 0) return (0); cifa_disp(cifa_head);cout next = NULL;p - type = type;strcpy(p-word,temp);cifa_add(p);return (1);int alph(void) /识别标识符 - 17 -int i=0;char temp10;int type = 1;tempi = ch;i+;GetChar();while (ch = a & ch = A & ch = 0 & ch next = NULL;p - type = type;strcpy(p-word,te

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号