import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFileChooser;
/**
*
* @author __USER__
*/
public class Ganalysis extends javax.swing.JFrame {
private static List<String> prt = new ArrayList<String>();
private static List<First> first = new ArrayList<First>();
private static List<First> follow = new ArrayList<First>();
private static List<TableE> table = new ArrayList<TableE>();
private int flag = 0;//用于判断是First集还是FOLLOW集
/** Creates new form LL1 */
public Ganalysis() {
initComponents();
}
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jButton1 = new javax.swing.JButton();//写入文法按钮
jScrollPane1 = new javax.swing.JScrollPane();//读入文法框
jTextArea1 = new javax.swing.JTextArea();//读入文法文本区
jButton2 = new javax.swing.JButton();//写入字符串按钮
jTabbedPane1 = new javax.swing.JTabbedPane();
jScrollPane2 = new javax.swing.JScrollPane();//First集框
jTextArea2 = new javax.swing.JTextArea();//First集文本区
jScrollPane3 = new javax.swing.JScrollPane();//Follow集框
jTextArea3 = new javax.swing.JTextArea();//Follow集文本区
jScrollPane5 = new javax.swing.JScrollPane();//预测分析表框
jTextArea5 = new javax.swing.JTextArea();//预测分析表文本区
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jScrollPane4 = new javax.swing.JScrollPane();//读入字符串框
jTextArea4 = new javax.swing.JTextArea();//读入字符串文本区
jButton3 = new javax.swing.JButton();//语法分析按钮
jButton4 = new javax.swing.JButton();//清空文本按钮
jScrollPane6 = new javax.swing.JScrollPane();//栈变化框
jTextArea6 =new javax.swing.JTextArea();//栈变化文本区
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("写入文法");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton2.setText("写入字符串");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jTextArea2.setColumns(20);
jTextArea2.setRows(5);
jScrollPane2.setViewportView(jTextArea2);
jTabbedPane1.addTab("First集", jScrollPane2);
jTextArea3.setColumns(20);
jTextArea3.setEditable(false);
jTextArea3.setRows(5);
jScrollPane3.setViewportView(jTextArea3);
jTabbedPane1.addTab("Follow集", jScrollPane3);
jTextArea5.setColumns(20);
jTextArea5.setRows(5);
jScrollPane5.setViewportView(jTextArea5);
jTabbedPane1.addTab("预测分析表", jScrollPane5);
jTextArea5.setColumns(20);
jTextArea5.setRows(5);
jScrollPane6.setViewportView(jTextArea6);
jTabbedPane1.add("栈变化过程",jScrollPane6);
jTextArea4.setColumns(20);
jTextArea4.setEditable(false);
jTextArea4.setRows(5);
jScrollPane4.setViewportView(jTextArea4);
jButton3.setText("语法分析");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton4.setText("清空文本区");
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
setLayout(null);
setSize(460, 680);
add(jTabbedPane1);
add(jButton1);
add(jButton2);
add(jButton3);
add(jButton4);
add(jScrollPane1);
add(jScrollPane4);
add(jLabel1);
add(jLabel2);
jTabbedPane1.setBounds(10, 10, 420, 420);
jButton1.setBounds(5, 430, 100, 40);
jButton2.setBounds(110, 430, 100, 40);
jButton3.setBounds(215, 430, 100, 40);
jButton4.setBounds(320, 430, 100, 40);
jScrollPane1.setBounds(5, 500, 180, 140);
jScrollPane4.setBounds(190, 500, 180, 140);
jLabel1.setBounds(5, 460, 180, 40);
jLabel2.setBounds(190, 460, 180, 40);
}// </editor-fold>
//GEN-END:initComponents
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1.setText(null);
jTextArea2.setText(null);
jTextArea3.setText(null);
jTextArea4.setText(null);
jTextArea5.setText(null);
jTextArea6.setText(null);
first.clear();
System.out.println(first);
follow.clear();
System.out.println(follow);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
FindFirstP();
//求First集
int frontSize = first.size();/*次数控制判定,全部first集已经不再发生变化,停止调用FindFirstS()函数!*/
FindFirstS();
int secondSize = first.size();
if (frontSize != secondSize) {
FindFirstS();
}
//求Follow集
frontSize = follow.size();/*次数控制判定,全部first集已经不再发生变化,停止调用FindFirstS()函数!*/
findFollowP();
secondSize = follow.size();
if (frontSize != secondSize) {
findFollowP();
}
jTextArea2.setText("First集:\n");
printF(first);
flag = 1;
jTextArea3.append("Follow集:\n");
printF(follow);
createTable();
printT();//打印表
analysis();
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
this.reads();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.read();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Ganalysis().setVisible(true);
}
});
}
//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JScrollPane jScrollPane6;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JTextArea jTextArea3;
private javax.swing.JTextArea jTextArea4;
private javax.swing.JTextArea jTextArea5;
private javax.swing.JTextArea jTextArea6;
private stack stack;
private int step,ptr;
private String input="";
private boolean symbol;
private String exp1;
private String rightexp;//字符串右部
// End of variables declaration//GEN-END:variables
private String fileName = "C:\\";
public void read() {//读取文件函数
BufferedReader br = null;
String line = "";
JFileChooser jfc = new JFileChooser(fileName);
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = jfc.showOpenDialog(this);
if (result == JFileChooser.CANCEL_OPTION)
return;
File file = jfc.getSelectedFile();
fileName = file.getAbsolutePath();
try {
br = new BufferedReader(new FileReader(fileName));
jLabel1.setText("读入的文法是:");
while ((line = br.readLine()) != null) {
jTextArea1.append(line + "\n");
pretreatment(line);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (br != null) {
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
语法分析词法分析器java.rar (23个子文件)
语法分析词法分析器java
词法分析
WAnalysis
.project 385B
src
JavaWordAnalyser.java 15KB
.settings
org.eclipse.jdt.core.prefs 629B
.classpath 301B
bin
JavaWordAnalyser.class 12KB
~$词法分析报告.doc 162B
~WRL0005.tmp 43KB
~$语法分析报告.doc 162B
~WRL0001.tmp 110KB
语法分析
GAnalysis
.project 385B
src
stack.java 587B
Ganalysis.java 24KB
.settings
org.eclipse.jdt.core.prefs 629B
.classpath 489B
bin
Ganalysis$First.class 4KB
Ganalysis$TableE.class 2KB
Ganalysis$5.class 510B
Ganalysis$1.class 690B
Ganalysis$3.class 690B
Ganalysis$2.class 690B
stack.class 1KB
Ganalysis.class 17KB
Ganalysis$4.class 690B
共 23 条
- 1
资源评论
- 小凡同学丶2014-11-28还不错,用来学习是很好的
- 穆哲2014-06-15还不错。但是还得花点时间来研究下代码
- xianjiaotongliu2012-09-30该资源是一个很好用的自动生成软件,可以自动生成分析器
- wszjl19922015-10-24课程设计正好是这个课题,挺有用的,不错还是要改下才能交,资源很不错!
- 养个执壶2014-06-23很不错,交作业了,功能好用。。
qq58268961
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功