已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实 验 二 THOMPSON 算法的实现实验日期: 2011 年 10 月 31日 评分 批阅教师签字 一、实验目的掌握THOMPSON 算法原理和方法二、实验内容1输入字母表上的正规式r,输出一个接受L(r)的NFA2采用C+语言,实现该算法3 编制测试程序4调试程序三、实验环境计算机、Windows 操作系统、Visual C+ 程序集成环境。四、实验原理(或程序框图)及步骤THOMPSON 算法是语法制导的,也就是说它沿着正则表达式的语法分析树自底向上的递归的地进行处理。对于每个子表达式,该算法构造一个只有一个接受状态的NFA。输入:字母表上的一个正则表达式。输出:一个接受L(r)的NFA N。方法:首先对r进行语法分析,分解出组成它的子表达式。构造一个NFA的规则分为基本规则和归纳规则两组。基本规则处理不包含运算符的子表达式,而归纳规则根据一个给定表达式的直接子表达式的NFA构造出这个表达式的NFA。五、程序源代码核心代码如下:class nfapublic:nfa();nfa(const nfa &);static void delete_arc_node(PArc_node &);static void delete_all_vnode(PV_node &);static bool and_append(my_expression, my_expression &);static void add_count(PV_node &, int);static void delete_vnode(PV_node &);static bool infix_to_postfix(my_expression, my_expression &);bool expression_to_nfa(my_expression);bool reg_to_nfa(my_expression);void print_nfa();private:PV_node nfa_data;void operator=(const nfa &);bool nfa: expression_to_nfa(my_expression inreg)PV_node test_V_node,test_V_node1;PV_node test_PV_node,test_PV_node1;PArc_node test_PArc_node;int count;char temp_char;V_stack test_stack;while (!inreg.empty()inreg.retrieve(temp_char);if (temp_char = .)test_stack.top(test_V_node1);test_stack.pop();test_stack.top(test_V_node);test_PV_node = test_V_node;while (test_PV_node-nextv != NULL)test_PV_node = test_PV_node-nextv;count = test_PV_node-data;add_count(test_V_node1,count);test_PV_node-firstarc = test_V_node1-firstarc;test_PV_node-nextv = test_V_node1-nextv;delete test_V_node1;test_stack.pop();test_stack.push(test_V_node);else if (temp_char = |)test_stack.top(test_V_node1);test_stack.pop();test_stack.top(test_V_node);test_PV_node = test_V_node;while (test_PV_node-nextv != NULL)test_PV_node = test_PV_node-nextv;count = test_PV_node-data + 2;add_count(test_V_node,1);add_count(test_V_node1,count);test_PV_node-nextv = test_V_node1;test_PV_node1 = test_V_node1;while (test_PV_node1-nextv != NULL)test_PV_node1 = test_PV_node1-nextv;count = test_PV_node1-data + 1;test_PV_node1-nextv = test_V_node;test_V_node = test_PV_node1;test_V_node-firstarc = new ArcNode;test_V_node-firstarc-adjvex = #;test_V_node-firstarc-info = 1;test_V_node-firstarc-nextarc = new ArcNode;test_PArc_node = test_V_node-firstarc-nextarc;test_PArc_node-adjvex = #;test_PArc_node-info = test_V_node1-data;test_PArc_node-nextarc = NULL;test_stack.pop();test_stack.push(test_V_node);else if (temp_char = *)test_stack.top(test_V_node);test_PV_node = test_V_node;while (test_PV_node-nextv != NULL)test_PV_node = test_PV_node-nextv;test_PV_node-firstarc = new ArcNode;test_PV_node-firstarc-adjvex = #;test_PV_node-firstarc-info = 0;test_PV_node-firstarc-nextarc = NULL;test_PArc_node = test_PV_node-firstarc;count = test_PV_node-data + 1;test_PV_node-nextv = new VNode;test_PV_node-nextv-data = count;test_PV_node-nextv-firstarc = NULL;test_PV_node-nextv-nextv = NULL;test_PArc_node-nextarc = new ArcNode;test_PArc_node-nextarc-adjvex = #;test_PArc_node-nextarc-info = count;test_PArc_node-nextarc-nextarc = NULL;add_count(test_V_node,1);test_PV_node = new VNode;test_PV_node-nextv = test_V_node;test_V_node = test_PV_node;test_PV_node-data = 0;test_PV_node-firstarc = new ArcNode;test_PV_node-firstarc-adjvex = #;test_PV_node-firstarc-info = 1;test_PArc_node = test_PV_node-firstarc;test_PArc_node-nextarc = new ArcNode;test_PArc_node-nextarc-adjvex = #;test_PArc_node-nextarc-info = count + 1;test_PArc_node-nextarc-nextarc = NULL;test_stack.pop();test_stack.push(test_V_node);else test_V_node = new VNode;test_V_node-data=0;test_V_node-firstarc = new ArcNode;test_V_node-firstarc-adjvex = temp_char;test_V_node-firstarc-info = 1;test_V_node-firstarc-nextarc = NULL;test_V_node-nextv = new VNode;test_V_node-nextv-data = 1;test_V_node-nextv-firstarc = NULL;test_V_node-nextv-nextv = NULL;test_stack.push(test_V_node);inreg.serve();return true;六、实验数据、结果分析本次实验以课本3.6节课后练习3.6
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 成年人沉稳心态养成 遇事从容淡定处事课件
- 人权:每个人都有的基本权利课件
- 国际防灾减灾日主题阅读课件
- 2025年广西壮族自治区地理专升本真题及答案
- 2026成都彭州中学高一入学英语分班考试真题含答案
- 2026年安徽省芜湖市高职单招英语真题及参考答案
- 2025年安宁《电缆安装工岗》专业培训试卷
- 2026高等教育时政热点题库含答案
- 2025年湖北(专升本)史地真题及答案
- 呼吸道合胞病毒(RSV)婴幼儿防护课件
- 2026木材干燥技术创新与质量控制标准报告
- 2026广东江门市公安局警务辅助人员招聘161人(第二批)考试备考题库及答案解析
- 26新五年级上册语文第一次月考检测卷1-2单元
- 【2026公开课】Unit 2 My friends PA Let's learn 教学课件
- 第5课 中国人民站起来了 第2课时 课件(内嵌视频)2026-2027学年道德与法治五年级上册统编版
- IEC 60335-2-9-2024 中文版 家用和类似用途电器安全 烤箱、灶、炉及类似器具特殊要求
- 《5. 睡眠要充足》课件2
- 劲性钢骨梁柱施工方案
- 2026年人文知识竞赛通关题库含答案详解【培优】
- 2026中国印刷电路板组装服务行业现状规模与投资前景预测报告
- 危货运输安全全程管控方案
评论
0/150
提交评论