📄 ll1gui.java
字号:
textArea.append(temp[j]+" ");
}
textArea.append("}\n");
}
}
});
}
return jButton3;
}
/**
* This method initializes jButton4
*
* @return javax.swing.JButton
*/
private JButton getJButton4() {
if (jButton4 == null) {
jButton4 = new JButton();
jButton4.setText("分析表");
jButton4.setBounds(3, 131, 85, 19);
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
mark=1;
mycard.next(jContentPane);
String termin=l.termin+"#";
String[] couName=new String[termin.length()+1] ;
couName[0]=" ";
for(int i=1;i<=termin.length();i++){
couName[i]="";
couName[i]+=termin.charAt(i-1);
}
Object[][] rowData=new Object[l.nonter.length()][termin.length()+1];
int n;
for(int i=0;i<=l.count-1;i++){
for( n=0 ;;n++)
if(l.nonter.charAt(n)==l.left[i])
break;
for(int j=0;j<l.select[i].length();j++){
for(int m=0;m<termin.length();m++) {
if(l.select[i].charAt(j)==termin.charAt(m))
{rowData[n][0]=""+l.nonter.charAt(n);
rowData[n][m+1]="->"+l.right[i];
l.M[n][m]=l.right[i];
}
}
}
}
jTable = new JTable(rowData,couName);
if(jScrollPane!=null){
jPanel2.remove(jScrollPane);
}
jScrollPane = new JScrollPane();
jScrollPane.setBounds(8, 11, 281, 138);
jScrollPane.setViewportView(jTable);
jPanel2.add(jScrollPane, null);
char temp[]=l.termin.toCharArray();
String columnName[]=new String[l.termin.length()];
for(int i=0;i<l.termin.length();i++){
columnName[i]+=l.termin.charAt(i);
}
}
});
}
return jButton4;
}
/**
* This method initializes textArea
*
* @return java.awt.TextArea
*/
private TextArea getTextArea() {
if (textArea == null) {
textArea = new TextArea();
textArea.setBounds(93, 14, 193, 158);
}
return textArea;
}
/**
* This method initializes jPanel2
*
* @return javax.swing.JPanel
*/
private JPanel getJPanel2() {
if (jPanel2 == null) {
jPanel2 = new JPanel();
jPanel2.setLayout(null);
jPanel2.setSize(228, 108);
jPanel2.setName("jPanel2");
jPanel2.add(getJButton5(), null);
}
return jPanel2;
}
/**
* This method initializes jTable
*
* @return javax.swing.JTable
*/
/**
* This method initializes jButton5
*
* @return javax.swing.JButton
*/
private JButton getJButton5() {
if (jButton5 == null) {
jButton5 = new JButton();
jButton5.setBounds(112, 178, 69, 26);
jButton5.setText("back");
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
mycard.previous(jContentPane);
}
});
}
return jButton5;
}
/**
* This method initializes jButton6
*
* @return javax.swing.JButton
*/
private JButton getJButton6() {
if (jButton6 == null) {
jButton6 = new JButton();
jButton6.setBounds(3, 108, 85, 19);
jButton6.setText("ll(1)判别");
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if(l.isLL1()){
JOptionPane.showMessageDialog(null,"该文法是LL(1)文法","判别结果",1) ;
}
else
JOptionPane.showMessageDialog(null,"该文法不是LL(1)文法","判别结果",1) ;
}
});
}
return jButton6;
}
/**
* This method initializes jTextField
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(116, 184, 160, 20);
}
return jTextField;
}
/**
* This method initializes jButton7
*
* @return javax.swing.JButton
*/
private JButton getJButton7() {
if (jButton7 == null) {
jButton7 = new JButton();
jButton7.setBounds(3, 184, 100, 20);
jButton7.setText("输入串分析");
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
if(mark==0){
JOptionPane.showMessageDialog(null,"请先建立预测分析表","提示",1) ;
}
else{
mycard.next(jContentPane);
String str=jTextField.getText();
char temp[]=str.toCharArray();
String[] couNum={"步骤","分析栈","剩余输入串","推导或匹配 "};
int p=0;
int buzhou=0;
char top;
String tui;
Integer op=new Integer(buzhou);
String tem=jTextField.getText();
Stack st=new Stack();
st.push(l.start);
DefaultTableModel model=new DefaultTableModel();
if(jScrollPane!=null){
jPanel2.remove(jScrollPane);
}
jTable=new JTable(model);
jScrollPane = new JScrollPane();
jScrollPane.setBounds(8, 11, 281, 138);
jScrollPane.setViewportView(jTable);
jPanel2.add(jScrollPane, null);
model.addColumn("步骤");
model.addColumn("符号栈");
model.addColumn("输入串");
model.addColumn("推导或匹配");
while(true){
buzhou++;
op=new Integer(buzhou);
String tep=st.print();
top=st.pop();
String laststr;
laststr="";
for(int j=p;j<str.length();j++){
laststr+=str.charAt(j);
}
if(top=='#'&&str.charAt(p)=='#'){
model.addRow(new Object[]{op,tep,laststr,"success"});
break;}
if(top=='#'&&str.charAt(p)!='#'){
model.addRow(new Object[]{op,tep,laststr,"unsuccess"});
break;}
if (l.belong(top,l.nonter) ){
tui=l.SearchTable(top,str.charAt(p));
if(tui==null){
model.addRow(new Object[]{op,tep,laststr,"error"});
break;
}
model.addRow(new Object[]{op,tep,laststr, top+"->"+tui });
if(tui.charAt(0)!='@'){
st.push(tui);
}
continue;
}
if(l.belong(top,l.termin)&&top==str.charAt(p)){
model.addRow(new Object[]{op,tep,laststr, str.charAt(p)+"匹配" });
p++;}
else if(l.belong(top,l.nonter)&&l.SearchTable(top,str.charAt(p))=="error"){
model.addRow(new Object[]{op,tep,laststr,"unsuccess" });
break;
}
else if(l.belong(top,l.termin)&&top!=str.charAt(p)){
model.addRow(new Object[]{op,tep,laststr,"unsuccess" });
break;
}
}
}
}
});
}
return jButton7;
}
/**
* This method initializes jTextField1
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField1() {
if (jTextField1 == null) {
jTextField1 = new JTextField();
jTextField1.setBounds(159, 67, 25, 22);
jTextField1.setText("");
}
return jTextField1;
}
/**
* This method initializes jTextField2
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField2() {
if (jTextField2 == null) {
jTextField2 = new JTextField();
jTextField2.setBounds(159, 98, 116, 19);
jTextField2.setText("");
}
return jTextField2;
}
/**
* This method initializes jTextField3
*
* @return javax.swing.JTextField
*/
private JTextField getJTextField3() {
if (jTextField3 == null) {
jTextField3 = new JTextField();
jTextField3.setBounds(158, 130, 117, 16);
jTextField3.setText("");
}
return jTextField3;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -