我正在尝试打印存储在 2 个单独类的链接列表中的变量(包含字符串变量的标题节点和包含整数值的链接节点)。我收到一个错误,说它找不到符号。
我不确定出了什么问题。如果您需要更多信息,请告诉我。
这是完整的代码:
package symboltable;
public class SymbolTable {
IdentifierHeaderNode[] table = new IdentifierHeaderNode[50];
IdentifierHeaderNode ptr;
public SymbolTable(){
for(int x = 0; x <= 49; x++)
}
public void addIdentifier(String info, int lineNumber){
LineNode ptr;
LineNode newNode;
boolean found = false;
int y = 0;
int x = 0;
//Look for Identifier In Array If Found, Add New Node to End
while(table[y] != null && !found){
if (table[y].info.equals(info)){
newNode = new LineNode (lineNumber, null);
found = true;
}
else
y++;
}
//If Identifier Not Found, Create New Identifier and Add Node to End
IdentifierHeaderNode ident1;
if(found == false){
newNode = new LineNode (lineNumber, null);
ident1 = new IdentifierHeaderNode();
//Add New Identifier to Table
while(!found && x <= 50){
if (table[x] == null){
table[x] = ident1;
found = true;
}
else
x = x + 1;
}
}
}
public void print(){
System.out.println("Symbol Table");
System.out.println("------------------------------------------------");
System.out.println("Identifier Name \t Line Appears On");
int x = 0;
boolean end = false;
while(table[x] != null &&!end){
System.out.print(table[x].info);
System.out.println( table[x].lineNumber);
}
}
}
这是错误所在:
if (table[y].info.equals(info))
System.out.print(table[x].info);
System.out.println( table[x].lineNumber);
每个都说“找不到符号”这些变量在它们的每个类中声明。
IdentifierHeaderNode 类:包符号表;
公共类 IdentifierHeaderNode {
public static String info;
public LineNode first;
public IdentifierHeaderNode(){
}
public IdentifierHeaderNode (String info, LineNode node){
this.info = info;
first = node;
}
public String getInfo(){
return info;
}
}