symtable works but not multiple variable

This commit is contained in:
Minh VU
2025-04-05 13:41:23 +02:00
parent 56df584b9f
commit bc7d1045ee
17 changed files with 104 additions and 1653 deletions

View File

@@ -40,6 +40,7 @@ public interface Interface{
public interface InstrVisitor<H,S>{
public S visitReturn(Return_instrImp e, H h);
public S visitAssign(AssignImp e, H h);
public S visitDeclaration(DeclarationImp e,H h);
}
//////////Expression

View File

@@ -184,6 +184,25 @@ public class Program{
}
}
public static record DeclarationImp(Type t, String s) implements Instruction{
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitDeclaration(this, h);
}
@Override
public String prettyprinter(String indent) {
return "declare "+t.toString()+s;
}
@Override
public ArrayList<InstructionLLVM> toLLVM() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'toLLVM'");
}
}
public static record Type_voidImp() implements Type{
public String prettyprinter() {
@@ -241,8 +260,7 @@ public class Program{
@Override
public Integer visitReturn(Return_instrImp e, Map<String, Integer> h) {
ExprEval exprEval = new ExprEval();
return e.e().accept(exprEval, h);
return e.accept(this, h);
}
@Override
public Integer visitAssign(AssignImp e, Map<String, Integer> h) {
@@ -250,6 +268,10 @@ public class Program{
//TODO
return 1;
}
@Override
public Integer visitDeclaration(DeclarationImp e, Map<String, Integer> h) {
return e.accept(this, h);
}
}

View File

@@ -45,4 +45,15 @@ public class SymTable {
}
return false;
}
public String print_all(){
StringBuilder str = new StringBuilder();
for(int i= stackMap.size()-1; i>=0; i--){
str.append("level ").append(i).append("\n");
for(String s: stackMap.get(i).keySet()){
str.append(s).append(" ").append(stackMap.get(i).get(s)).append("\n");
}
}
return str.toString();
}
}

View File

@@ -0,0 +1,15 @@
package TP2.asd;
import TP2.asd.Interface.*;
import TP2.asd.Program.Type_intImp;
import TP2.asd.SymTable.*;
public class test_symtable{
private static final Type Type_intImp = null;
public static void main(String[] args){
SymTable test_symTable = new SymTable();
test_symTable.next_layer();
//test_symTable.peppapeek();
test_symTable.addVar("a", Type_intImp);
System.out.print(test_symTable.print_all());
}
}