print read et SymTable
This commit is contained in:
@@ -4,24 +4,41 @@ import java.util.Stack;
|
||||
|
||||
import org.pcollections.*;
|
||||
import TP2.asd.Interface.Type;
|
||||
import TP2.asd.Program.Type_intImp;
|
||||
|
||||
|
||||
public class SymTable {
|
||||
private PStack<PMap<String,Type>> stackMap;
|
||||
|
||||
public static class ValueTable{
|
||||
public Type type;
|
||||
public int id;
|
||||
public ValueTable(Type type,int id){
|
||||
this.type = type;
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
|
||||
private PStack<PMap<String,ValueTable>> stackMap;
|
||||
private int id=1;
|
||||
public SymTable(){
|
||||
this.stackMap= ConsPStack.empty();
|
||||
}
|
||||
|
||||
public int getNewId(){
|
||||
int a = this.id;
|
||||
this.id++;
|
||||
return a;
|
||||
}
|
||||
|
||||
public String addNewTempVar(/*Type type*/){
|
||||
//TODO
|
||||
String newVar = "temp"+this.id;
|
||||
//this.addVar(newVar,new Type_intImp()); //TODO
|
||||
id++;
|
||||
this.addVar(newVar,new Type_intImp()); //TODO
|
||||
return newVar;
|
||||
}
|
||||
|
||||
public void next_layer(){
|
||||
stackMap.plus(HashTreePMap.empty());
|
||||
public PStack next_layer(){
|
||||
return stackMap.plus(HashTreePMap.empty());
|
||||
}
|
||||
|
||||
public void quit_layer() throws Exception{
|
||||
@@ -30,14 +47,19 @@ public class SymTable {
|
||||
}
|
||||
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
|
||||
}
|
||||
public PMap<String,Type> peppapeek(){
|
||||
|
||||
public PMap<String,ValueTable> peppapeek(){
|
||||
if(stackMap.isEmpty()){
|
||||
System.out.println("TEST...............................");
|
||||
this.next_layer();
|
||||
}
|
||||
return stackMap.getLast();
|
||||
}
|
||||
|
||||
public void addVar(String s, Type t){
|
||||
//Save temporary if not PMap wont save
|
||||
PMap<String, Type> pmap = this.peppapeek();
|
||||
pmap= pmap.plus(s/*+"_"+this.id*/,t);
|
||||
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()));
|
||||
@@ -56,11 +78,11 @@ public class SymTable {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Stack<PMap<String,Type>> stackmap(){
|
||||
public Stack<PMap<String,ValueTable>> stackmap(){
|
||||
return this.stackmap();
|
||||
}
|
||||
|
||||
public Type getvar_Type(String s){
|
||||
public ValueTable getvar_Type(String s){
|
||||
for(int i= stackMap.size()-1; i>=0; i--){
|
||||
if(stackMap.get(i).containsKey(s)){
|
||||
return stackMap.get(i).get(s);
|
||||
|
||||
Reference in New Issue
Block a user