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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

南昌大学编译原理实验语法分析含代码文档格式.docx

1、1、 分析文法,将给出的文法转化为LL(1)文法;2、 学习预测分析程序的结构,设计合理的预测分析程序;3、 编写测试程序,包括表达式的读入和结果的输出;4、 测试程序运行效果,测试数据可以参考下列给出的数据。六、测试数据 输入数据:编辑一个文本文文件expression.txt,在文件中输入如下内容: 10;1+2;(1+2)*3+(5+6*7);(1+2)*3+4;1+2+3+(*4+5);(a+b)*(c+d);(ab3+de4)*5)+1;正确结果:(1)10;输出:正确(2)1+2;(3)(1+2)*3+(5+6*7);(4)(1+2)*3+4错误(5)1+2+3+(*4+5)(6)

2、(a+b)*(c+d)(7)(ab3+de4)*5)+1七、实验报告要求实验报告应包括以下几个部分:1、 给定文法的LL(1)形式;2、 预测分析程序的算法和结构;3、 程序运行流程;4、 程序的测试结果和问题;5、 实验总结。package compile2;import java.util.Stack;public class text2 /* * 给定文法GE: */ static String gram = E-TA, A-+TAT-FBB-*FB, F-P(E) ; static String followE = )# static String followEA = static

3、String followT = + static String followTB = static String followF = * static String firstE = i( static String firstEA = static String firstT = static String firstTB = static String firstF = static String list = , E, null, null, , null, null ,A, null, TBF, null, null ; public static void main(String

4、args) throws Exception String infile = D:/expression.txt; String outfile = /result2.txt Stack tmpword = new Stack20; expression = new Stack20; for (int i = 0; i tmpword.length; i+) tmpwordi = new Stack(); expressioni = new Stack 2) String tmp = expressioni.toArray(new String0); printArray(tmp); isLL

5、1(tmpwordi); i+; public static void printArray(String s) s.length; i+) System.out.print(si); System.out.println(); public static void isLL1(Stack tmpword) String input = tmpword.toArray(new String0); int inputCount = 0; status = new Stack= 0; i-) status.push( + lista0a1.charAt(i); /inputCount+; else

6、 flag = false; result = false; if (result) System.out.println(正确 else错误 public static boolean isVt(String s) for (int i = 1; list0.length - 1; if (s.equals(list0i) return true; return false; public static int indexInList(String m, String a) int i = 0, j = 0; for (int c = 1; c list.length; c+) if (m.

7、equals(listc0) i = c; list0.length ; if (a.equals(list0c) j = c; return new int i, j ;import java.io.*;import java.util.*;public class main static String key_word = mainifthenwhiledointelse static String cal_word = -/=!=+=-=*=/=/program.txt/result.txt Stack word = new Stack5; Stack expression = new

8、Stackword.length; word.length; wordi = new Stack scan(infile, outfile, word, expression); public static void scan(String infile,String outfile, Stack word, Stack expression) throws Exception java.io.File file = new java.io.File(infile); Scanner input = new Scanner(file); java.io.PrintWriter output =

9、 new PrintWriter(outfile); int count = 0; wordcount.push( while (input.hasNext() String tmp = input.next(); int i = 0; while (i tmp.length() if (tmp.charAt(i) 1) /检查十进制数字 String num = while (tmp.charAt(i) 0) num += tmp.charAt(i); i+; if (i = tmp.length() break; output.println( + 1 + + num + wordcoun

10、t.push( expressioncount.push(num); if (i + 2 tmp.length()/ 检查十六进制数字 if (tmp.charAt(i) = tmp.charAt(i + 1) = x i += 2; String num = while (tmp.charAt(i) ) | (tmp.charAt(i) fa) num += tmp.charAt(i); i+; if (i = tmp.length() break; output.println( + 3 + wordcount.push( expressioncount.push(num); if (i

11、+ 1 tmp.length()/ 检查八进制数字 while (tmp.charAt(i) 7 + 2 + / 检查关键字和变量 if (i if (i tmp.length() & & tmp.charAt(i) tmp_word += tmp.charAt(i); boolean is_keyword = false; for (int j = 0; j wordcount.push(key_wordj); expressioncount.push(key_wordj); is_keyword = true; if (!is_keyword) output.println( + 0 +

12、+ tmp_word + wordcount.push( expressioncount.push(tmp_word); / 检查运算符以及 if (i + 1 if (tmp.charAt(i + 1) = = for (int j = 0; cal_word.length; if (cal_wordj.equals( + tmp.charAt(i) + tmp.charAt(i + 1) output.println( + cal_wordj + , + wordcount.push(cal_wordj); expressioncount.push( if (wordcount.peek(

13、) = wordcount.pop(); wordcount.push( count+; i += 2; break; for (int j = 0; if (cal_wordj.equals( + tmp.charAt(i) wordcount.push(cal_wordj); expressioncount.push(cal_wordj); if (wordcount.peek() = wordcount.pop(); wordcount.push( count+; input.close(); output.close();八、思考题1、 如果使用递归下降分析法来进行语法分析,为什么文法必须先转化为LL(1)文法再做递归下降分析?

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

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