Merge branch 'main' of https://gitlab2.istic.univ-rennes1.fr/tuvu/tp2-vsl-pds
This commit is contained in:
@@ -1,5 +1,34 @@
|
||||
package TP2.Error;
|
||||
|
||||
import TP2.asd.SymTable;
|
||||
import TP2.asd.Interface.ExprVisitor;
|
||||
import TP2.asd.Program.BinopExpressionImp;
|
||||
import TP2.asd.Program.ConstImp;
|
||||
import TP2.asd.Program.VarImp;
|
||||
|
||||
public class TypeChecking {
|
||||
|
||||
private SymTable st;
|
||||
|
||||
/*
|
||||
public class TypeCheckExpr implements ExprVisitor<SymTable ,TypeCheckExprDiag>{
|
||||
|
||||
@Override
|
||||
public TypeCheckExprDiag visitConst(ConstImp e, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitConst'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckExprDiag visitVar(VarImp e, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitVar'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckExprDiag visitBinOp(BinopExpressionImp e, SymTable h) {
|
||||
TypeCheckExprDiag tce1 = e.e1().accept(this, h) ;
|
||||
TypeCheckExprDiag tce2 = e.e2().accept(this, h) ;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -37,6 +37,9 @@ public interface Interface{
|
||||
public S visitDeclaration(DeclarationImp instr,H h);
|
||||
public S visitPrint(PrintImp instr, H h);
|
||||
public S visitRead(ReadImp instr,H h);
|
||||
public S visitIfThen(IfThenImp instr, H h);
|
||||
public S visitIfThenElse(IfThenElseImp instr, H h);
|
||||
public S visitWhile(WhileImp instr, H h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,6 +74,23 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitIfThen(IfThenImp instr, String indent) {
|
||||
String str = indent + "IF ";
|
||||
str +=(instr.e().accept(this, ""));
|
||||
str +=" THEN " + (instr.i1().accept(this, ""));
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitIfThenElse(IfThenElseImp instr, String indent) {
|
||||
String str = indent + "IF ";
|
||||
str +=(instr.e().accept(this, ""));
|
||||
str +=" THEN " + (instr.i1().accept(this, ""));
|
||||
str +=" ELSE "+ (instr.i2().accept(this, ""));
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitRead(ReadImp instr, String indent) {
|
||||
String str = indent+"READ ";
|
||||
@@ -84,6 +101,15 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitWhile(WhileImp instr, String indent) {
|
||||
String str = indent+"WHILE ";
|
||||
str += (instr.e().accept(this, ""));
|
||||
str+= " DO "+ (instr.i1().accept(this, ""));
|
||||
str+= " DONE";
|
||||
return str;
|
||||
}
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@Override
|
||||
|
||||
@@ -88,6 +88,27 @@ public class Program{
|
||||
}
|
||||
}
|
||||
|
||||
public static record IfThenImp(Expression e, Instruction i1) implements Instruction {
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitIfThen(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record IfThenElseImp(Expression e, Instruction i1, Instruction i2) implements Instruction {
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitIfThenElse(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record WhileImp(Expression e, Instruction i1) implements Instruction {
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitWhile(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
//Type
|
||||
public static record Type_voidImp() implements Type{
|
||||
@Override
|
||||
@@ -103,4 +124,5 @@ public class Program{
|
||||
return v.visitInt(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package TP2.asd;
|
||||
import java.util.Stack;
|
||||
|
||||
|
||||
import org.pcollections.*;
|
||||
import TP2.asd.Interface.Type;
|
||||
import TP2.asd.Program.Type_intImp;
|
||||
@@ -25,7 +23,6 @@ public class SymTable {
|
||||
this.symTable = symTable;
|
||||
this.var = var;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private PStack<PMap<String,ValueTable>> stackMap;
|
||||
@@ -66,14 +63,6 @@ public class SymTable {
|
||||
return stackMap.plus(HashTreePMap.empty());
|
||||
}
|
||||
|
||||
public void quit_layer() throws Exception{
|
||||
if(stackMap.isEmpty()){
|
||||
throw new Exception();
|
||||
}
|
||||
stackMap.minus(stackMap.indexOf(stackMap.getLast()));
|
||||
}
|
||||
|
||||
|
||||
public PMap<String,ValueTable> peppapeek(){
|
||||
if(stackMap.isEmpty()){
|
||||
return this.next_layer().getLast();
|
||||
|
||||
@@ -108,6 +108,25 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitIfThen(IfThenImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitIfThen'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitIfThenElse(IfThenElseImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitIfThenElse'");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitWhile(WhileImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitWhile'");
|
||||
}
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user