This commit is contained in:
Vu Tuan Minh
2025-04-07 17:33:38 +02:00
parent b3ed282f9a
commit addf4bdee1
4 changed files with 9 additions and 21 deletions

View File

@@ -7,10 +7,10 @@ import TP2.asd.Interface.Type;
import TP2.asd.Program.Type_intImp;
public class SymTable {
private Stack<PMap<String,Type>> stackMap;
private PStack<PMap<String,Type>> stackMap;
private int id=1;
public SymTable(){
this.stackMap= new Stack<>();
this.stackMap= ConsPStack.empty();
}
public String addNewTempVar(/*Type type*/){
@@ -22,17 +22,17 @@ public class SymTable {
}
public void next_layer(){
stackMap.push(HashTreePMap.empty());
stackMap.plus(HashTreePMap.empty());
}
public void quit_layer() throws Exception{
if(stackMap.isEmpty()){
throw new Exception();
}
stackMap.pop();
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
}
public PMap<String,Type> peppapeek(){
return stackMap.peek();
return stackMap.getLast();
}
public void addVar(String s, Type t){
@@ -41,9 +41,9 @@ public class SymTable {
pmap= pmap.plus(s/*+"_"+this.id*/,t);
//this.id++;
//Delete old ones
stackMap.pop();
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
//Push the new one
stackMap.push(pmap);
stackMap.plus(pmap);
}
//Usually look for var in highest level , if not found research.