parser + asd non testé non builder

This commit is contained in:
Vu Tuan Minh
2025-04-01 16:52:50 +02:00
parent 95fee3f1ae
commit 02d57fa858
13 changed files with 1374 additions and 60 deletions

View File

@@ -1,29 +1,40 @@
package TP2.asd;
import java.util.ArrayList;
import java.util.Map;
import java.util.Stack;
import java.util.stream.Collectors;
public record Program(ArrayList<Function> functions) {
}
record Function(Type type, String nom, ArrayList<Instruction> instructions){
public String prettyprinter(){
return "FUNC " +type.prettyprinter() +" "+ nom
+ instructions.stream().map(Instruction::prettyprinter).collect(Collectors.joining("\n"));
// Map: appel prettyprinter pour isntruction, combiner dans 1 paragraph avec \n au milieu
public Function(Type type, String name, Instruction instruction) {
this(type, name, new ArrayList<>() {{ add(instruction); }});
}
}
record Return_instr(Expression e) implements Instruction{
public String prettyprinter(){
return "RETURN" +e.prettyprinter();
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
return v.visitFunction(this, h);
}
}
record Expression(){
public String prettyprinter(){
return "";
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);
}
}
@@ -37,4 +48,4 @@ record Type_int() implements Type{
public String prettyprinter() {
return "INT";
}
}
}