This commit is contained in:
Vu Tuan Minh
2025-04-01 17:52:45 +02:00
parent 2a901e4a37
commit 3f9072c7bd
7 changed files with 161 additions and 178 deletions

View File

@@ -1,49 +1,48 @@
package TP2.asd;
import java.util.ArrayList;
import TP2.asd.Interface.*;
public record Program(ArrayList<Function> functions) {
}
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 class Program{
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 <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";
}
}
}
record Const(int c) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitConst(this, h);
}
}
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);
}
}
record Return_instr(Expression e) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitReturn(this,h);
}
}
record Type_void() implements Type{
public String prettyprinter() {
return "VOID";
}
}
record Type_int() implements Type{
public String prettyprinter() {
return "INT";
}
}