mips without optimize
This commit is contained in:
136
midend/symbol/SymbolTable.java
Normal file → Executable file
136
midend/symbol/SymbolTable.java
Normal file → Executable file
@@ -1,68 +1,68 @@
|
||||
package midend.symbol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import error.Error;
|
||||
import error.ErrorType;
|
||||
import error.Errors;
|
||||
|
||||
public class SymbolTable {
|
||||
private ArrayList<Symbol> symbolList;
|
||||
private HashMap<String, Symbol> symbolMap;
|
||||
private int tableId;
|
||||
private boolean isReleased;
|
||||
private SymbolTable parentTable;
|
||||
|
||||
public SymbolTable(int tableId) {
|
||||
this.tableId = tableId;
|
||||
isReleased = false;
|
||||
symbolList = new ArrayList<>();
|
||||
symbolMap = new HashMap<>();
|
||||
parentTable = null;
|
||||
}
|
||||
|
||||
public int getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public boolean isReleased() {
|
||||
return isReleased;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
isReleased = true;
|
||||
}
|
||||
|
||||
public void addSymbol(Symbol symbol, Errors errors) {
|
||||
if (symbolMap.containsKey(symbol.getName())) {
|
||||
errors.addError(new Error(symbol.getLine(), ErrorType.b));
|
||||
return;
|
||||
}
|
||||
symbolList.add(symbol);
|
||||
symbolMap.put(symbol.getName(), symbol);
|
||||
}
|
||||
|
||||
public void setParentTable(SymbolTable parentTable) {
|
||||
this.parentTable = parentTable;
|
||||
}
|
||||
|
||||
public SymbolTable getParentTable() {
|
||||
return parentTable;
|
||||
}
|
||||
|
||||
public Symbol getSymbol(String name) {
|
||||
if (symbolMap.containsKey(name)) {
|
||||
return symbolMap.get(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String info = "";
|
||||
for (Symbol symbol : symbolList) {
|
||||
info += tableId + " " + symbol.toString();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
package midend.symbol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import error.Error;
|
||||
import error.ErrorType;
|
||||
import error.Errors;
|
||||
|
||||
public class SymbolTable {
|
||||
private ArrayList<Symbol> symbolList;
|
||||
private HashMap<String, Symbol> symbolMap;
|
||||
private int tableId;
|
||||
private boolean isReleased;
|
||||
private SymbolTable parentTable;
|
||||
|
||||
public SymbolTable(int tableId) {
|
||||
this.tableId = tableId;
|
||||
isReleased = false;
|
||||
symbolList = new ArrayList<>();
|
||||
symbolMap = new HashMap<>();
|
||||
parentTable = null;
|
||||
}
|
||||
|
||||
public int getTableId() {
|
||||
return tableId;
|
||||
}
|
||||
|
||||
public boolean isReleased() {
|
||||
return isReleased;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
isReleased = true;
|
||||
}
|
||||
|
||||
public void addSymbol(Symbol symbol, Errors errors) {
|
||||
if (symbolMap.containsKey(symbol.getName())) {
|
||||
errors.addError(new Error(symbol.getLine(), ErrorType.b));
|
||||
return;
|
||||
}
|
||||
symbolList.add(symbol);
|
||||
symbolMap.put(symbol.getName(), symbol);
|
||||
}
|
||||
|
||||
public void setParentTable(SymbolTable parentTable) {
|
||||
this.parentTable = parentTable;
|
||||
}
|
||||
|
||||
public SymbolTable getParentTable() {
|
||||
return parentTable;
|
||||
}
|
||||
|
||||
public Symbol getSymbol(String name) {
|
||||
if (symbolMap.containsKey(name)) {
|
||||
return symbolMap.get(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String info = "";
|
||||
for (Symbol symbol : symbolList) {
|
||||
info += tableId + " " + symbol.toString();
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user