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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

编译原理实验报告实验三最新版.docx

1、编译原理实验报告实验三最新版中南大学编译原理课程实验实验报告题 目 实验三 学生姓名 陈亮名 学生学号 专业班级 1005 完成日期 2012/6/2 实验三 算符优先分析法设计与实现一、实验目的加深对语法分析器工作过程的理解;加强对算符优先分析法实现语法分析程序的掌握;能够采用一种编程语言实现简单的语法分析程序;能够使用自己编写的分析程序对简单的程序段进行语法翻译。二、实验内容在实验1的基础上,用算符优先分析法编制语法分析程序,语法分析程序的实现可以采用任何一种编程语言和工具。三、实验要求:1. 对语法规则有明确的定义;2. 编写的分析程序能够对实验一的结果进行正确的语法分析;3. 对于遇到

2、的语法错误,能够做出简单的错误处理,给出简单的错误提示,保证顺利完成语法分析过程;四、实验步骤1. 定义目标语言的语法规则;A.关键字后不能跟字符串运算符B.数字后不能跟关键字,数字,字符串,标示符C.字符串后不能跟关键字,数字,字符串,标示符D.标示符后不能跟数字,字符串2.依次读入实验一的分析结果,根据预测分析的方法进行语法分析,直到源程序结束;读入程序如下:package com.demo;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.

3、io.FileOutputStream;import java.io.IOException;public class copy public boolean cop(String src,String des) File sorFile,desFile; sorFile=new File(src); desFile=new File(des); FileInputStream fis=null; FileOutputStream fos=null; int n=0; byteb=new byte4*1024; try fis=new FileInputStream(src); fos=new

4、 FileOutputStream(des); while (n=fis.read(b)!=-1) fos.write(b, 0, n); / tyfkfuuofiiu /* * fhshtjsjtrjrs */ fos.flush(); fis.close(); fos.close(); catch (FileNotFoundException e) e.printStackTrace(); catch (IOException e) e.printStackTrace(); return true; public static void main(String args) copy cp=

5、new copy(); String src=args0; String des=args1; if (cp.cop(src, des) public 文件复制成功=String string; /(这一句有错误) System.out.println(文件复制成功); else System.out.println(shibai); 词法分析:进行语法分析:3.对遇到的语法错误做出错误处理。注:由于java整套语言出错的情况太多,以上只考虑了部分出错情况分析器代码如下:zpackage demo;import java.awt.Dimension;import java.awt.Toolki

6、t;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;

7、import java.io.IOException;import java.io.UnsupportedEncodingException;import javax.swing.JButton;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JOptionPane;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;public class WordAnalys

8、es extends JFrame private JButton choosefileButton; private JButton analyseButton; private JButton grammarButton; private JButton exportButton; private JTextField jtf; private JTextArea outpuTextArea; JScrollPane jsp;/ 新建一个滚动条界面,将文本框传入 String s = ; String s2 = ; String word= new String8*10243; priva

9、te int index = 0; File file; int m = 0; int f= 0; FileInputStream fileInputStream; / 关键字 private String code1 = new String if, int, for, while, do, return, break, continue, package, public, class, static, void, main, new, null, abstract, boolean, byte, case, catch, char, default, double, else, enum,

10、 extends, final, finally, float, implements, import, instanceof, interface, long, native, private, protected, strictfp, short, super, switch, synchronized, this, throw, throws, transient, try, volatile ; / 运算符 private String code4 = new String +, -, *, /, =, , &, &, |, or, and, xor, ! ; / 标点 private

11、 String code5 = new String , ;, , , (, ), , , . ; private StringBuffer sBuffer ; public WordAnalyses(String title) super(title); Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension scrnsize = toolkit.getScreenSize(); setSize(600, 700); setLocation(scrnsize.width - 600) / 2, (scrnsize.height - 7

12、00) / 2); myframe(); add(choosefileButton).setBounds(25, 10, 100, 25); add(analyseButton).setBounds(175, 10, 100, 25); add(grammarButton).setBounds(325, 10, 100, 25); add(exportButton).setBounds(475, 10, 100, 25); add(jsp).setBounds(0, 45, 590, 600); add(jtf).setBounds(0, 35, 600, 10); / add(jsp).se

13、tBounds(0, 45, 600, 665); setVisible(true); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); public void myframe() choosefileButton = new JButton(选择文件); choosefileButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e)

14、 f= 1; int n; sBuffer = new StringBuffer(s2); try JFileChooser jfc = new JFileChooser(); jfc.showOpenDialog(WordAnalyses.this); file = jfc.getSelectedFile(); fileInputStream = new FileInputStream(file); while (n = fileInputStream.read() != -1) sBuffer.append( + (char) n); catch (FileNotFoundExceptio

15、n e1) e1.printStackTrace(); catch (IOException e1) e1.printStackTrace(); try s2 = new String(sBuffer.toString().getBytes(ISO8859-1); catch (UnsupportedEncodingException e1) / TODO Auto-generated catch block e1.printStackTrace(); sBuffer = new StringBuffer(s2); ); analyseButton = new JButton(开始分析); a

16、nalyseButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) if (f =0) JOptionPane.showMessageDialog(rootPane, 请先选择要分析的文件!); else System.out.println(sBuffer.length(); m = 0; for (int i = 0; i sBuffer.length(); i+) s = s + sBuffer.charAt(i); if (s.equals( ) | s.equal

17、s( ) | s.equals(rn) | s.equals(n)| s.equals(r) s = ; continue; /注释 if (s.equals(/) & ( + sBuffer.charAt(i + 1).equals(/) i = i + 2; s = /; while (!( + sBuffer.charAt(i).equals(r) s = s + sBuffer.charAt(i); i+; System.out.println( + 2 , + s + ); outpuTextArea.setText(outpuTextArea.getText() + ( + 2 ,

18、 + s + ) + rn); wordindex1= s; wordindex2= 2; index +; s = ; continue; /段注释 if (s.equals(/) & ( + sBuffer.charAt(i + 1).equals(*) i = i + 2; s = /*; while (!( + sBuffer.charAt(i).equals(*) & ( + sBuffer .charAt(i + 1).equals(/) s = s + sBuffer.charAt(i); i+; i = i + 2; s = s + */; System.out.println

19、( + 3 , + s + ); outpuTextArea.setText(outpuTextArea.getText() + ( + 3 , + s + ) + rn); wordindex1= s; wordindex2= 3; index +; s = ; continue; /关键字 if (!s.equals() for (int j = 0; j code1.length; j+) if (s.equals(code1j) & ( + sBuffer.charAt(i + 1).equals( ) | ( + sBuffer.charAt(i + 1) .equals(r) |

20、( + sBuffer .charAt(i + 1).equals(n) System.out.println( + 1 , + code1j + ); outpuTextArea.setText(outpuTextArea.getText() + ( + 1 , + code1j + ) + rn); wordindex1= s; wordindex2= 1; index +; s = ; break; /运算符 if (!s.equals() String sss = ; for (int j = 0; j code4.length; j+) if (s.equals(code4j) if

21、 (s.equals(or) | s.equals(and) | s.equals(xor) System.out.println( + 4 , + s + ); outpuTextArea.setText(outpuTextArea .getText() + ( + 7 , + s + ) + rn); wordindex1= s; wordindex2= 7; index +; s = ; break; sss = sss + code4j; for (int k = 0; k = 48 & ( + sBuffer).charAt(i) 57) if ( + sBuffer).charAt

22、(i + 1) 57) System.out.println( + 3 + , + s + ); outpuTextArea.setText(outpuTextArea.getText() + ( + 4 + , + s + ) + rn); wordindex1= s; wordindex2= 4; index +; s = ; continue; /分隔符 if (!s.equals() for (int j = 0; j code5.length; j+) if (s.equals(code5j) System.out.println( + 5 + , + code5j + ); out

23、puTextArea.setText(outpuTextArea.getText() + ( + 8 + , + code5j + ) + rn); wordindex1= s; wordindex2= 8; index +; s = ; break; /字符串 if (s.equals() i+; while (!( + sBuffer.charAt(i).equals() s = s + sBuffer.charAt(i); i+; s = s + sBuffer.charAt(i); System.out.println( + 字符串 + , + s + ); outpuTextArea.setText(outpuTextArea.getText()

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

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