symtable works but not multiple variable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
15
src/main/java/TP2/asd/test_symtable.java
Normal file
15
src/main/java/TP2/asd/test_symtable.java
Normal 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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user