error LL1 in function and proto in Parser. too weird.
This commit is contained in:
@@ -8,18 +8,18 @@ import TP2.llvm.ProgramLLVM.DefineLLVMImp;
|
||||
public class SymTable {
|
||||
|
||||
private PStack<PMap<String,ValueVarMap>> varMap;
|
||||
private PMap<String,ValueFunMap> fuctionsMap;
|
||||
private PMap<String,ValueFunMap> functionsMap;
|
||||
private int id=1;
|
||||
private int idLabel = 1;
|
||||
|
||||
public SymTable(){
|
||||
this.varMap= ConsPStack.singleton(HashTreePMap.empty());
|
||||
this.fuctionsMap = HashTreePMap.empty();
|
||||
this.functionsMap = HashTreePMap.empty();
|
||||
}
|
||||
public SymTable(PStack<PMap<String,ValueVarMap>> varMap, PMap<String,ValueFunMap> fuctionsMap, int id, int idLabel){
|
||||
public SymTable(PStack<PMap<String,ValueVarMap>> varMap, PMap<String,ValueFunMap> functionsMap, int id, int idLabel){
|
||||
this.varMap= varMap;
|
||||
this.id = id;
|
||||
this.fuctionsMap = fuctionsMap;
|
||||
this.functionsMap = functionsMap;
|
||||
this.idLabel = idLabel;
|
||||
}
|
||||
|
||||
@@ -34,12 +34,12 @@ public class SymTable {
|
||||
}
|
||||
|
||||
public SymTable newBlock() {
|
||||
return new SymTable(varMap.plus(HashTreePMap.empty()), fuctionsMap, id, idLabel);
|
||||
return new SymTable(varMap.plus(HashTreePMap.empty()), functionsMap, id, idLabel);
|
||||
}
|
||||
|
||||
public SymTable outBlock() {
|
||||
if (varMap.size() > 1) {
|
||||
return new SymTable(varMap.minus(0), fuctionsMap, id, idLabel);
|
||||
return new SymTable(varMap.minus(0), functionsMap, id, idLabel);
|
||||
} else {
|
||||
System.err.println("Vide");
|
||||
return this;
|
||||
@@ -73,9 +73,9 @@ public class SymTable {
|
||||
|
||||
|
||||
public SymTable addFunction(DefineLLVMImp function, Boolean isProto){
|
||||
ValueFunMap value = this.fuctionsMap.get(function.name());
|
||||
ValueFunMap value = this.functionsMap.get(function.name());
|
||||
if(value == null || (value!=null && value.isProto && !isProto)){
|
||||
return new SymTable(this.varMap, this.fuctionsMap.plus(function.name(),new ValueFunMap(function,isProto)), this.id, this.idLabel);
|
||||
return new SymTable(this.varMap, this.functionsMap.plus(function.name(),new ValueFunMap(function,isProto)), this.id, this.idLabel);
|
||||
}
|
||||
else{
|
||||
if(value.isProto) System.err.println("[VSL compile error] : Le prototype "+function.name()+" existe déjà");
|
||||
@@ -86,7 +86,7 @@ public class SymTable {
|
||||
}
|
||||
|
||||
public ValueFunMap getFunction(String name){
|
||||
return this.fuctionsMap.get(name);
|
||||
return this.functionsMap.get(name);
|
||||
}
|
||||
|
||||
public int getId(){
|
||||
@@ -129,7 +129,7 @@ public class SymTable {
|
||||
}
|
||||
String realName = nomVar + id;
|
||||
top = top.plus(nomVar, new ValueVarMap(new Type_intImp(), id, false));
|
||||
SymTable newSym = new SymTable(varMap.minus(0).plus(0, top), fuctionsMap, id+1, idLabel);
|
||||
SymTable newSym = new SymTable(varMap.minus(0).plus(0, top), functionsMap, id+1, idLabel);
|
||||
return new Result(newSym, realName);
|
||||
}
|
||||
|
||||
@@ -150,12 +150,10 @@ public class SymTable {
|
||||
}
|
||||
|
||||
public Boolean isPresentVar(String nomVar){
|
||||
boolean x= false;
|
||||
while(!x){
|
||||
for (PMap<String,ValueVarMap> scope : varMap){
|
||||
x=scope.containsKey(nomVar);
|
||||
for (PMap<String,ValueVarMap> scope : varMap) {
|
||||
if (scope.containsKey(nomVar)) {
|
||||
return true;
|
||||
}
|
||||
if (x) return true;
|
||||
}
|
||||
System.err.println(nomVar+" n'est pas trouvé");
|
||||
return false;
|
||||
@@ -189,7 +187,7 @@ public class SymTable {
|
||||
return this;
|
||||
}
|
||||
top = top.plus(nomVar, new ValueVarMap(type, id, isParam));
|
||||
return new SymTable(varMap.minus(0).plus(0, top), fuctionsMap, id+1, idLabel);
|
||||
return new SymTable(varMap.minus(0).plus(0, top), functionsMap, id+1, idLabel);
|
||||
}
|
||||
|
||||
public String print_all(){
|
||||
@@ -199,7 +197,7 @@ public class SymTable {
|
||||
|
||||
int scopeLevel = varMap.size();
|
||||
for (PMap<String, ValueVarMap> scope : varMap) {
|
||||
str.append("Scope Level ").append(scopeLevel--).append(":\n");
|
||||
str.append("Block Level ").append(scopeLevel--).append(":\n");
|
||||
for (String varName : scope.keySet()) {
|
||||
ValueVarMap value = scope.get(varName);
|
||||
str.append("Name: ").append(varName)
|
||||
@@ -211,7 +209,7 @@ public class SymTable {
|
||||
}
|
||||
|
||||
str.append("FUNCTIONS:\n");
|
||||
for (String funcName : fuctionsMap.keySet()) {
|
||||
for (String funcName : functionsMap.keySet()) {
|
||||
str.append(" Name: ").append(funcName).append("\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user