symTable en cours
This commit is contained in:
@@ -18,11 +18,25 @@ public class SymTable {
|
||||
}
|
||||
}
|
||||
|
||||
public static class Result{
|
||||
public SymTable symTable;
|
||||
public String var;
|
||||
public Result(SymTable symTable, String var){
|
||||
this.symTable = symTable;
|
||||
this.var = var;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PStack<PMap<String,ValueTable>> stackMap;
|
||||
private int id=1;
|
||||
public SymTable(){
|
||||
this.stackMap= ConsPStack.empty();
|
||||
}
|
||||
public SymTable(PStack<PMap<String,ValueTable>> stackMap, int id){
|
||||
this.stackMap= stackMap;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getNewId(){
|
||||
int a = this.id;
|
||||
@@ -30,14 +44,14 @@ public class SymTable {
|
||||
return a;
|
||||
}
|
||||
|
||||
public String addNewTempVar(/*Type type*/){
|
||||
public Result addNewTempVar(/*Type type*/){
|
||||
//TODO
|
||||
String newVar = "temp"+this.id;
|
||||
this.addVar(newVar,new Type_intImp()); //TODO
|
||||
return newVar;
|
||||
String newVar = "temp"+getNewId();
|
||||
SymTable newSymTab = this.addVar(newVar,new Type_intImp()); //TODO
|
||||
return new Result(newSymTab,newVar);
|
||||
}
|
||||
|
||||
public PStack next_layer(){
|
||||
public PStack<PMap<String,ValueTable>> next_layer(){
|
||||
return stackMap.plus(HashTreePMap.empty());
|
||||
}
|
||||
|
||||
@@ -51,20 +65,27 @@ public class SymTable {
|
||||
public PMap<String,ValueTable> peppapeek(){
|
||||
if(stackMap.isEmpty()){
|
||||
System.out.println("TEST...............................");
|
||||
this.next_layer();
|
||||
return this.next_layer().getLast();
|
||||
}
|
||||
return stackMap.getLast();
|
||||
}
|
||||
|
||||
public void addVar(String s, Type t){
|
||||
public SymTable addVar(String s, Type t){
|
||||
PStack<PMap<String,ValueTable>> newpstack = null;
|
||||
if(this.stackMap.isEmpty()){
|
||||
newpstack = this.next_layer();
|
||||
}
|
||||
else newpstack = this.stackMap;
|
||||
|
||||
//Save temporary if not PMap wont save
|
||||
PMap<String, ValueTable> pmap = this.peppapeek();
|
||||
pmap= pmap.plus(s/*+"_"+this.id*/,new ValueTable(t, getNewId()));
|
||||
//this.id++;
|
||||
//Delete old ones
|
||||
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
|
||||
newpstack = newpstack.minus(stackMap.indexOf(stackMap.getLast()));
|
||||
//Push the new one
|
||||
stackMap.plus(pmap);
|
||||
newpstack = newpstack.plus(pmap);
|
||||
return new SymTable(newpstack,this.id);
|
||||
}
|
||||
|
||||
//Usually look for var in highest level , if not found research.
|
||||
|
||||
Reference in New Issue
Block a user