📄 grammartable.java
字号:
package Sentence;
//行列都是从一算起的。
public class GrammarTable {
GrammarTable(int row,int col){
columnCount = col;
rowCount = row;
data = new Object[rowCount+1][columnCount+1];
}
GrammarTable(int row,int col,Rule[] rul,String[] unf,String[] fin){
columnCount = col;
rowCount = row;
data = new Object[rowCount+1][columnCount+1];
rules = rul;
unFinals = unf;
finals = fin;
}
public void setRowName(String str,int num){
data[num][0] = str;
}
public void setColumnName(String str,int num){
data[0][num] = str;
}
public void setValueAt(Object obj,int row,int col){
data[row][col] = obj;
}
public void setValueAt(Object obj,String rowName,String colName){
int i,j;
i = rowNameToNum(rowName);
j = colNameToNum(colName);
data[i][j] = obj;
}
public String getRowName(int num){
String name = (String)data[num][0];
return name;
}
public String getColumnName(int num){
String name = (String)data[0][num];
return name;
}
public Object getValueAt(int row,int col){
Object item = data[row][col];
return item;
}
public Object getValueAt(String rowName,String colName){
int i,j;
i = rowNameToNum(rowName);
j = colNameToNum(colName);
Object item = data[i][j];
return item;
}
protected int rowNameToNum(String rowName){
int i=1;
for(int k=1;k<=rowCount;k++){
if(rowName.compareTo(getRowName(k))==0){
i=k;
break;
}
}
return i;
}
protected int colNameToNum(String colName){
int i=1;
for(int k=1;k<rowCount;k++){
if(colName.compareTo(getColumnName(k))==0){
i=k;
break;
}
}
return i;
}
protected int columnCount,rowCount;
protected Object[][] data;
protected Rule[] rules;
protected String[] finals;
protected String[] unFinals;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -