fragment_0 manque code intermédiaire
This commit is contained in:
9
src/main/java/TP2/asd/Interface.java
Normal file
9
src/main/java/TP2/asd/Interface.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package TP2.asd;
|
||||
|
||||
interface Instruction {
|
||||
public String prettyprinter();
|
||||
}
|
||||
|
||||
interface Type{
|
||||
public String prettyprinter();
|
||||
}
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user