print et Read en cours
This commit is contained in:
@@ -93,6 +93,17 @@ instruction returns [Instruction out]:
|
||||
}
|
||||
)*
|
||||
{$out = new PrintImp(printer);}
|
||||
| //READ
|
||||
READ i1=ident
|
||||
{
|
||||
ArrayList<String> read= new ArrayList<String>();
|
||||
read.add($i1.out);
|
||||
}(VIRGULE i2=ident
|
||||
{
|
||||
read.add($i2.out);
|
||||
})*
|
||||
{$out = new ReadImp(read);}
|
||||
|
||||
;
|
||||
|
||||
//Priorité lit(val, const ou paranthese) -> td_exp (*/%) -> exp (+-)
|
||||
|
||||
@@ -36,6 +36,7 @@ public interface Interface{
|
||||
public S visitAssign(AssignImp instr, H h);
|
||||
public S visitDeclaration(DeclarationImp instr,H h);
|
||||
public S visitPrint(PrintImp instr, H h);
|
||||
public S visitRead(ReadImp instr,H h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -61,12 +61,24 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
@Override
|
||||
public String visitPrint(PrintImp instr, String indent) {
|
||||
String str = indent + "PRINT ";
|
||||
for (String elem: instr.t()){
|
||||
str += "\"" +elem +"\"";
|
||||
for(int i = 0; i<instr.t().size(); i++){
|
||||
String g = "";
|
||||
Object o = instr.t().get(i);
|
||||
if(o instanceof String){
|
||||
str += "\"" + instr.t().get(i) +"\"";
|
||||
}
|
||||
else if(o instanceof Expression){
|
||||
str += g + ((Expression)instr.t().get(i)).accept(this,"");
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitRead(ReadImp instr, String h) {
|
||||
return "Tibo, tu peux implenter le truc stp";
|
||||
}
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@Override
|
||||
|
||||
@@ -74,13 +74,20 @@ public class Program{
|
||||
}
|
||||
}
|
||||
|
||||
public static record PrintImp(ArrayList<String> t) implements Instruction{
|
||||
public static record PrintImp(ArrayList t) implements Instruction{
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitPrint(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record ReadImp(ArrayList t) implements Instruction{
|
||||
@Override
|
||||
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
|
||||
return v.visitRead(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
//Type
|
||||
public static record Type_voidImp() implements Type{
|
||||
@Override
|
||||
|
||||
@@ -93,10 +93,19 @@ public class toLLVM_Visitor implements ProgramVisitor<SymTable,ProgramLLVMImpl>
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitPrint(PrintImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitPrint'");
|
||||
ArrayList<InstructionLLVM> l = new ArrayList<>();
|
||||
l.add(new PrintLLVMImp(new ArrayList())); //TODO
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> visitRead(ReadImp instr, SymTable h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitRead'");
|
||||
}
|
||||
|
||||
//EXPRESSION
|
||||
|
||||
@Override
|
||||
public InstrAndVal visitConst(ConstImp e, SymTable h) {
|
||||
ValLLVM val = new ValLLVMImpl(new IntLLVMImpl(),e.c());
|
||||
|
||||
@@ -29,6 +29,8 @@ public interface Interface {
|
||||
public S visitReturnLLVM(ReturnLLVMImp instr, H h);
|
||||
public S visitAssignLLVM(AssignLVMImp instr, H h);
|
||||
public S visitStoreLLVM(StoreLLVMImp instr, H h);
|
||||
public S visitPrintLLVM(PrintLLVMImp instr, H h);
|
||||
public S visitReadLLVM(ReadLLVMImp instr, H h);
|
||||
}
|
||||
|
||||
//////////ExpressionLLVM (expression)
|
||||
|
||||
@@ -100,6 +100,17 @@ TypeLLVMVisitor<String,String>
|
||||
return "load" + " i" + e.nbBits() + ", i"+ e.nbBits2() + "* %" + e.val().accept(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitPrintLLVM(PrintLLVMImp instr, String h) {
|
||||
return INDENT+"print";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitReadLLVM(ReadLLVMImp instr, String h) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'visitReadLLVM'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitValLLVM(ValLLVMImpl e, String h) {
|
||||
return e.val() + "";
|
||||
@@ -121,4 +132,5 @@ TypeLLVMVisitor<String,String>
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -61,6 +61,21 @@ public class ProgramLLVM {
|
||||
}
|
||||
}
|
||||
|
||||
public static record PrintLLVMImp(ArrayList<String> l) implements InstructionLLVM{
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitPrintLLVM(this, h);
|
||||
}
|
||||
}
|
||||
|
||||
public static record ReadLLVMImp(ArrayList<String> l) implements InstructionLLVM{
|
||||
|
||||
@Override
|
||||
public <H, S> S accept(InstructionLLVMVisitor<H, S> v, H h) {
|
||||
return v.visitReadLLVM(this, h);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Expression :
|
||||
public static record BinOpLLVMImp(TypeLLVM type,Op op, ValLLVM val1,ValLLVM val2) implements ExpressionLLVM{
|
||||
|
||||
Reference in New Issue
Block a user