pretty printer

il manque \t
This commit is contained in:
Minh VU
2025-02-07 09:55:45 +01:00
parent 7dcf0385e4
commit 16ca8f7050
10 changed files with 105 additions and 3 deletions

View File

@@ -12,6 +12,11 @@ options {
}
entite: '<' ID '>';
// Whitespaces are ignored.
fragment WS: (' ' | '\n' | '\t' | '\r' | '\u000C');
WSS: WS+ { skip(); };
WSS: WS+ { skip(); };
ID: ('a'..'z'|'A'..'Z')('a'..'z'|'A'..'Z'|'0'..'9'|'_')*;

View File

@@ -0,0 +1,55 @@
package TP1;
import java.util.List;
public class ASD_Turtle implements TurtleASD {
sealed interface Turtle{}
sealed interface Phrase{}
sealed interface Affectation{}
sealed interface Complement{}
sealed interface Entity{}
record TurtleImp(List<PhraseImp> phrases) implements Turtle{}
record PhraseImp(EntityImp entity, List<AffectationImp> affs) implements Phrase{}
record AffectationImp(EntityImp entity, List<Complement> complements) implements Affectation{}
record Complement_EntityImp(EntityImp entity) implements Complement{}
record Complement_TextImp(String string) implements Complement{}
record EntityImp(String string) implements Entity{}
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

@@ -1,4 +1,4 @@
package TP1;
interface TurtleAST {
interface TurtleASD {
}