pretty printer
il manque \t
This commit is contained in:
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal 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
1
.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
TP1
|
||||
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal 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
16
.idea/gradle.xml
generated
Normal 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
5
.idea/misc.xml
generated
Normal 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
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
2
ASD.txt
2
ASD.txt
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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'|'_')*;
|
||||
55
src/main/java/TP1/ASD_Turtle.java
Normal file
55
src/main/java/TP1/ASD_Turtle.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package TP1;
|
||||
|
||||
interface TurtleAST {
|
||||
interface TurtleASD {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user