fini asd?

This commit is contained in:
Minh VU
2025-02-09 15:18:43 +01:00
parent c853e559e7
commit 043509ca82
2 changed files with 14 additions and 47 deletions

View File

@@ -18,7 +18,16 @@ public class ASD_Turtle implements TurtleASD {
return str;
}
}
record PhraseImp(EntityImp entity, List<AffectationImp> affs) implements Phrase{}
record PhraseImp(EntityImp entity, List<AffectationImp> affs) implements Phrase{
public String toString(){
String str = "< " + this.entity.toString() + " >\n";
for (AffectationImp aff : this.affs) {
str += aff.toString() + "\n";
}
str += ".";
return str;
}
}
record AffectationImp(EntityImp entity, List<Complement> complements) implements Affectation{
public String toString(){
String str= "< " + this.entity.toString() + " >";
@@ -41,53 +50,9 @@ public class ASD_Turtle implements TurtleASD {
return " \" " + this.string + " \"";
}
}
record EntityImp(String string) implements Entity{
record EntityImp(String string) implements Entity{
public String toString(){
return this.string;
}
}
public void prettyPrinter(TurtleImp t){
for (PhraseImp phrase : t.phrases) {
prettyPrinter(phrase);
}
}
public void prettyPrinter(PhraseImp phrase){
System.out.println("< " + phrase.entity + " >");
for (AffectationImp affectation : phrase.affs) {
prettyPrinter(affectation);
}
System.out.println(".");
}
public void prettyPrinter(AffectationImp affectation){
System.out.println("< " + affectation.entity + " >");
for (int i =0; i < affectation.complements.size(); i++) {
prettyPrinter(affectation.complements.get(i));
if (i < affectation.complements.size() - 1) {
System.out.print(", ");
}
}
System.out.println(";");
}
public void prettyPrinter(Complement complement){
if( complement instanceof Complement_EntityImp ce){
System.out.println(" < " + ce.entity + " >");
} else if ( complement instanceof Complement_TextImp ct){
System.out.println(" \" " + ct.string + " \"");
}
}
public void prettyPrint(EntityImp entity) {
System.out.print(entity.string);
}
}

View File

@@ -2,6 +2,8 @@ package TP1;
import java.io.IOException;
import javax.swing.text.html.parser.Entity;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CharStream;
@@ -14,7 +16,7 @@ public class Main {
* Buils example AST and illustrates the translator.
*/
public static void manualAST() {
System.out.println("Traducteur à compléter !");
Entity entity1 = new EntityImp("A");
}
/**