-
-
Save anonymous/a669b4220a56a52e02ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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