print read et SymTable

This commit is contained in:
trochas
2025-04-09 13:01:11 +02:00
parent 3232a9f9ec
commit f4a438df01
8 changed files with 77 additions and 47 deletions

View File

@@ -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);