Files
tp2-vsl-pds/src/main/java/TP2/asd/Program.java
Vu Tuan Minh ef07343d9f error 3
2025-04-01 18:17:15 +02:00

57 lines
1.6 KiB
Java

package TP2.asd;
import java.util.ArrayList;
import java.util.List;
import TP2.asd.Interface.*;
public class Program{
public static record ProgramImp(ArrayList<Instruction> instructions){
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
return v.visitProgram(this, h);
}
}
public static record Function(Type type, String nom, ArrayList<Instruction> instructions){
public Function(Type type, String name, Instruction instruction) {
this(type, name, new ArrayList<>() {{ add(instruction); }});
}
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
return v.visitFunction(this, h);
}
}
public static record Const(int c) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitConst(this, h);
}
}
public static record BinopExpression(Op op,Expression e1, Expression e2) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitBinOp(this, h);
}
}
public static record Return_instr(Expression e) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitReturn(this,h);
}
}
public static record Type_void() implements Type{
public String prettyprinter() {
return "VOID";
}
}
public static record Type_int() implements Type{
public String prettyprinter() {
return "INT";
}
}
}