clean todo Load
This commit is contained in:
@@ -11,8 +11,6 @@ import TP2.llvm.Interface.*;
|
||||
|
||||
public class Program{
|
||||
|
||||
static String INDENT = " ";
|
||||
|
||||
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
|
||||
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||
return v.visitProgram(this, h);
|
||||
@@ -106,77 +104,4 @@ public class Program{
|
||||
return v.visitInt(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Eval
|
||||
public static class ProgramEval implements ProgramVisitor<SymTable, Integer> {
|
||||
@Override
|
||||
public Integer visitProgram(ProgramImp e, SymTable h) {
|
||||
Integer result = null;
|
||||
SymTable symtable = new SymTable();
|
||||
FunctionEval functionEval = new FunctionEval();
|
||||
for (Function function : e.fonctions()) {
|
||||
result = function.accept(functionEval, h);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class FunctionEval implements FunctionVisitor<SymTable, Integer> {
|
||||
|
||||
@Override
|
||||
public Integer visitFunction(FunctionImp e, SymTable h) {
|
||||
h.next_layer();
|
||||
InstructionEval instructionEval = new InstructionEval();
|
||||
Integer result = null;
|
||||
for (Instruction instr : e.instructions()) {
|
||||
result = instr.accept(instructionEval, h);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class InstructionEval implements InstrVisitor<SymTable,Integer>{
|
||||
|
||||
@Override
|
||||
public Integer visitReturn(Return_instrImp e, SymTable h) {
|
||||
return e.accept(this, h);
|
||||
}
|
||||
@Override
|
||||
public Integer visitAssign(AssignImp e, SymTable h) {
|
||||
return e.accept(this, h);
|
||||
}
|
||||
@Override
|
||||
public Integer visitDeclaration(DeclarationImp e, SymTable h) {
|
||||
return e.accept(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class ExprEval implements ExprVisitor<SymTable,Integer>{
|
||||
public Integer visitConst(ConstImp c, SymTable h){
|
||||
return c.c();
|
||||
}
|
||||
|
||||
public Integer visitBinOp(BinopExpressionImp e, SymTable h) {
|
||||
switch(e.op()) {
|
||||
case Op.PLUS: return e.e1().accept(this, h)+e.e2().accept(this, h);
|
||||
case Op.MINUS: return e.e1().accept(this, h)-e.e2().accept(this, h);
|
||||
case Op.TIMES: return e.e1().accept(this, h)*e.e2().accept(this, h);
|
||||
case Op.DIV: return e.e1().accept(this, h)/e.e2().accept(this, h);
|
||||
case Op.MOD: return e.e1().accept(this, h)%e.e2().accept(this, h);
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer visitVar(VarImp v, SymTable h) {
|
||||
if (h.searchVar(v.name())) {
|
||||
return 0;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user