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

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

1
.idea/.name generated Normal file
View File

@@ -0,0 +1 @@
TP1

6
.idea/compiler.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="21" />
</component>
</project>

16
.idea/gradle.xml generated Normal file
View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

5
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="corretto-21" project-jdk-type="JavaSDK" />
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@@ -20,7 +20,7 @@ turtle ::= Turtle(phrase*)
phrase ::= Phrase(entity, aff*)
aff ::= Aff(entity, complement*)
complement ::= Complement(Entity)
|Text(String)
| Complement_Text(String)
entity ::= Entity(String)

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 {
}