Skip to content

Instantly share code, notes, and snippets.

Created November 4, 2014 02:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a669b4220a56a52e02ce to your computer and use it in GitHub Desktop.
Save anonymous/a669b4220a56a52e02ce to your computer and use it in GitHub Desktop.
public class SymbolTable {
public IdentifierHeaderNode[] symbol_table;
public SymbolTable(){
this.symbol_table = new IdentifierHeaderNode[50]; // table of 50 identifiers
}
public void add(String id, int line){
int loc = find(id); //location of string id
for(int i = 0; i < symbol_table.length; i++){
if(loc == -1){ // first time adding that type of string
if(symbol_table[i] == null){ //condition necessary to add
symbol_table[i] = new IdentifierHeaderNode(id, new LineNumNode(line, null));
break;
}
}
if(loc != -1){ //string has been added before
//symbol_table[loc].setNext(new LineNumNode(symbol_table[loc].getNext().getLineNum(), new LineNumNode(line, null))); // only works on two
}}
}
public int find(String str){
for(int i = 0; i < symbol_table.length; i++){
if (symbol_table[i] == null){
}
else {
if(symbol_table[i].getIdentifier().equals(str)){
return i;
}
}
}
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment