fragment_0 manque code intermédiaire

This commit is contained in:
Vu Tuan Minh
2025-03-31 03:35:30 +02:00
parent 6643190a3f
commit 95fee3f1ae
8 changed files with 147 additions and 17 deletions

View File

@@ -0,0 +1,9 @@
package TP2.asd;
interface Instruction {
public String prettyprinter();
}
interface Type{
public String prettyprinter();
}

View File

@@ -1,4 +1,40 @@
package TP2.asd;
public record Program() {
import java.util.ArrayList;
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
}
}
record Return_instr(Expression e) implements Instruction{
public String prettyprinter(){
return "RETURN" +e.prettyprinter();
}
}
record Expression(){
public String prettyprinter(){
return "";
}
}
record Type_void() implements Type{
public String prettyprinter() {
return "VOID";
}
}
record Type_int() implements Type{
public String prettyprinter() {
return "INT";
}
}