framer.java
来自「桂林电子科技大学编译原理完整JAVA源代码(词法、语法、语义) 此为完整版本」· Java 代码 · 共 768 行 · 第 1/3 页
JAVA
768 行
.add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
);
jPanel4Layout.setVerticalGroup(
jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 201, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
);
jMenu1.setMnemonic('F');
jMenu1.setText("\u6587\u4ef6(F)");
jMenuItem1.setMnemonic('N');
jMenuItem1.setText("\u65b0\u5efa\u6587\u4ef6(N)");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem2.setMnemonic('O');
jMenuItem2.setText("\u6253\u5f00\u6587\u4ef6(O)");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuItem3.setMnemonic('S');
jMenuItem3.setText("\u4fdd\u5b58\u6587\u4ef6(S)");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem3);
jMenuItem5.setMnemonic('X');
jMenuItem5.setText("\u53e6\u4fdd\u5b58\u4e3a(X)");
jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem5ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem5);
jMenuItem4.setMnemonic('E');
jMenuItem4.setText("\u9000\u51fa(E)");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem4);
jMenuBar1.add(jMenu1);
jMenu2.setMnemonic('R');
jMenu2.setText("\u8fd0\u884c(R)");
jMenu2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu2ActionPerformed(evt);
}
});
jMenuItem6.setMnemonic('C');
jMenuItem6.setText("\u8bcd\u6cd5\u5206\u6790(C)");
jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem6ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem6);
jMenuItem7.setMnemonic('Y');
jMenuItem7.setText("\u8bed\u6cd5\u5206\u6790(Y)");
jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem7ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem7);
jMenuBar1.add(jMenu2);
jMenu5.setText("\u7f16\u8f91(E)");
jMenuBar1.add(jMenu5);
jMenu6.setText("\u7a97\u53e3(W)");
jMenuBar1.add(jMenu6);
jMenu7.setText("\u5e2e\u52a9(H)");
jMenuBar1.add(jMenu7);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jToolBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jToolBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 41, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jTextArea1CaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jTextArea1CaretUpdate
// TODO 将在此处添加您的处理代码:
try {
int pos = jTextArea1.getCaretPosition();
//获取行数
int lineOfC = jTextArea1.getLineOfOffset(pos) + 1;
//获取列数
int col = pos - jTextArea1.getLineStartOffset(lineOfC - 1) + 1;
jTextArea1.setToolTipText("当前光标位置" + lineOfC + " 行 , " + col + " 列 ");
this.jLabel1.setText("当前光标位置 "+lineOfC+" 行, " + col + " 列 ");
} catch(Exception ex) {
this.jLabel1.setToolTipText("无法获得当前光标位置");
}
}//GEN-LAST:event_jTextArea1CaretUpdate
private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
// TODO 将在此处添加您的处理代码:
Celser c=new Celser();
c.P_p();
String err1="";
err1=c.err;
this.jTextArea2.setText(err1);
}//GEN-LAST:event_jMenuItem7ActionPerformed
private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
// TODO 将在此处添加您的处理代码:
this.jTextArea2.setText("");
String line,lie = "",message="",value,err ="",err1;
str="";err1="";
Scanner scan=new Scanner();
Lexer L=new Lexer();
ResultSet rs,rs1,rs2;
char ch[]=new char [500];
Sql sq=new Sql();
String sql,name;
sql="delete from 词法分析";
sq.executeSql(sql);
for(int j=0;j<500;j++) {
ch[j]='\0';
}
ch=this.getText().toCharArray();
scan.splist(ch);
String s[]=scan.getS();
int col[]=scan.getCol();
boolean flag=false;
for(int n=0;n<s.length;n++) {
if(s[n]!=null) {
scan.check(s[n]);
if(!s[n].equals("\n")) {
sql="insert into 词法分析(说明,内部码,名称,行,列,错误) values('"+scan.getMessage()+"','"+scan.getValue()+"','"+scan.getName()+"','"+scan.getLine()+"','"+col[n]+"','"+scan.getErr()+"')";
sq.executeSql(sql);
}
}
// System.out.print(s[n]);
}
sql="select * from 词法分析 where 名称 <> 'null'";
try{
rs=sq.getResult(sql);
rs.beforeFirst();
while(rs.next()) {
line=rs.getString("行");
name=rs.getString("名称");
value=rs.getString("内部码");
message=rs.getString("说明");
lie=rs.getString("列");
err=rs.getString("错误");
if(!err.equals("No")) {
err1+="Error: "+err+" "+name+" 在第"+line+"行"+lie+"列;\n";
flag=true;
this.jButton7.setEnabled(false);
this.jButton7.setToolTipText("不能进行语法分析");
this.jMenu7.setEnabled(false);
}
str+=message+" ( "+value+" , "+name+" )"+" ( "+line+"行 , "+lie+"列 )\n";
}
rs.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
if(!flag&&scan.getZushierr().equals("")) {
str=str+"词法分析成功!";
this.jButton7.setEnabled(true);
this.jMenuItem7.setEnabled(true);
}else {
str=str+err1+scan.getZushierr();
this.jButton7.setEnabled(false);
this.jButton7.setToolTipText("不能进行语法分析");
this.jMenuItem7.setEnabled(false);
}
//System.out.print(scan.getZushierr());
this.jTextArea2.setText(str);
str="";
}//GEN-LAST:event_jMenuItem6ActionPerformed
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
// TODO 将在此处添加您的处理代码:
System.exit(0);
}//GEN-LAST:event_jButton8ActionPerformed
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO 将在此处添加您的处理代码:
jFileChooser1.setVisible(true);
int state=jFileChooser1.showSaveDialog(null);
File fileName=jFileChooser1.getSelectedFile();
try{
FileWriter fw = new FileWriter(fileName);
BufferedWriter bw = new BufferedWriter(fw);
String str = this.jTextArea1.getText();
bw.write(str);
bw.close();
fw.close();
new JOptionPane().showMessageDialog(this,"保存成功");
} catch (IOException e1) {
new JOptionPane().showMessageDialog(this,"保存失败");
e1.printStackTrace();
}
}//GEN-LAST:event_jButton6ActionPerformed
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?