资源描述:
《编译原理词法分析实验》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、编译原理上机实验试题一、实验目的通过本实验使学生进一步熟悉和掌握程序设计语言的词法分析程序的设计原理及相关的设计技术,如何针对确定的有限状态自动机进行编程序;熟悉和掌握程序设计语言的语法分析程序的设计原理、熟悉和掌握算符优先分析方法。二、实验要求本实验要求:①要求能熟练使用C++程序设计语言编程;②在上机之前要有详细的设计报告(预习报告);③要编写出完成相应任务的程序并在计算机上准确地运行;④实验结束后要写出上机实验报告。三、实验题目针对下面文法G(S):S→v=EE→E+E│E-E│E*E│E/E│(E)│v│i其中,v为标识符,i为整型或实型数。
2、要求完成①使用自动机技术实现一个词法分析程序;②使用算符优先分析方法实现其语法分析程序;③在语法分析过程中同时完成常量表达式的计算。针对下面文法G(S):S→v=EE→E+E│E-E│E*E│E/E│(E)│v│i其中,v为标识符,i为整型或实型数。要求完成①使用自动机技术实现一个词法分析程序;②使用算符优先分析方法实现其语法分析程序;③在语法分析过程中同时完成常量表达式的计算。//编译原理课程设计,词法自动机。importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava
3、x.swing.event.*;importjava.io.*;importjava.util.*;classframeextendsJFrameimplementsActionListener{JButtonbutton1=newJButton("打开现有文件");JButtonbutton2=newJButton("现场输入文件");Choicech=newChoice();JButtonbutton=newJButton("执行");TextAreata=newTextArea();TextAreatb=newTextArea();JFileC
4、hooserchooser=newJFileChooser();FileInputStreamreadfile=null;intb;bytebuffer[]=newbyte[25000];Stringstr=null;Stringid[]={"asm","cout","main","FALSE","TRUE","include","boolean","default","float","operator","abs","static_cast","union","auto","delete","for","private","struct","uns
5、igned","bool","do","friend","protected","switch","using","break","double","goto","public","template","virtual","case","dynamic_cast","if","register","this","void","catch","else","inline","reinterpret_cast","throw","volatile","char","enum","int","return","true","wchar_t","class"
6、,"explicit","long","short","try","while","const","export","mutable","signed","typedef","const_cast","extern","namespace","sizeof","typeid","Continue","false","new","static","typename"};FileReaderfile=null;BufferedReaderin=null;Filef=null;frame(){super();Containerc=this.getConte
7、ntPane();ch.add("C语言常数识别");ch.add("C语言标识符识别");ch.add("C语言注释字母大写");ch.add("C语言保留字大写");c.setLayout(null);c.add(button1);button1.setBounds(5,5,120,25);button1.addActionListener(this);c.add(button2);button2.setBounds(130,5,120,25);button2.addActionListener(this);c.add(ch);ch.setBou
8、nds(260,5,120,25);c.add(button);button.setBounds(390,5