tested preety printer

This commit is contained in:
tuvu
2025-02-10 13:27:09 +01:00
parent 043509ca82
commit b087f2ddbe
6 changed files with 85 additions and 85 deletions

View File

@@ -1,7 +1,7 @@
{ {
"java.server.launchMode": "Standard", "java.server.launchMode": "Standard",
"java.gradle.buildServer.enabled": "on", "java.gradle.buildServer.enabled": "on",
"java.jdt.ls.java.home": "C:\\Program Files\\Java\\jdk-21", "java.jdt.ls.java.home": "/usr/lib/jvm/jdk-21.0.6-oracle-x64",
"antlr4.generation": { "antlr4.generation": {
"mode": "none" // Don't generate source file with the antlr4-vscode extension "mode": "none" // Don't generate source file with the antlr4-vscode extension
}, },

View File

@@ -12,37 +12,6 @@ options {
} }
LC : '<'
;
RC : '>'
;
P: '.'
;
V: ','
;
SEMI: ';'
;
G: '"'
;
prog : bloc EOF
;
bloc : sujet listvc P
;
sujet : LC entity RC
;
listvc : LC vc RC more
;
more : SEMI listvc
|
;
vc : LC verbe RC listc
;
listc : LC comp RC morec
;
morec : V comp
|
;
// Whitespaces are ignored. // Whitespaces are ignored.

View File

@@ -21,10 +21,13 @@ public class ASD_Turtle implements TurtleASD {
record PhraseImp(EntityImp entity, List<AffectationImp> affs) implements Phrase{ record PhraseImp(EntityImp entity, List<AffectationImp> affs) implements Phrase{
public String toString(){ public String toString(){
String str = "<" + this.entity.toString() + ">\n"; String str = "<" + this.entity.toString() + ">\n";
for (AffectationImp aff : this.affs) { for (int i =0; i < this.affs.size(); i++ ){
str += aff.toString() + "\n"; str += affs.get(i).toString();
if (i < this.affs.size() - 1) {
str += ";\n";
} }
str += "."; }
str += ".\n";
return str; return str;
} }
} }
@@ -37,7 +40,7 @@ public class ASD_Turtle implements TurtleASD {
str += ","; str += ",";
} }
} }
return str + ";"; return str;
} }
} }
record Complement_EntityImp(EntityImp entity) implements Complement{ record Complement_EntityImp(EntityImp entity) implements Complement{

View File

@@ -1,8 +1,7 @@
package TP1; package TP1;
import java.io.IOException; import java.io.IOException;
import java.util.List;
import javax.swing.text.html.parser.Entity;
import org.antlr.runtime.ANTLRFileStream; import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.ANTLRInputStream; import org.antlr.runtime.ANTLRInputStream;
@@ -10,13 +9,80 @@ import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException; import org.antlr.runtime.RecognitionException;
public class Main { import TP1.ASD_Turtle.*;
public class Main {
/** /**
* Buils example AST and illustrates the translator. * Buils example AST and illustrates the translator.
*
LC : '<'
;
RC : '>'
;
P: '.'
;
V: ','
;
SEMI: ';'
;
G: '"'
;
prog : bloc EOF
;
bloc : sujet listvc P
;
sujet : LC entity RC
;
listvc : LC vc RC more
;
more : SEMI listvc
|
;
vc : LC verbe RC listc
;
listc : LC comp RC morec
;
morec : V comp
|
;
*/ */
public static void manualAST() { public static void manualAST() {
Entity entity1 = new EntityImp("A"); //Ridoux <type> <personne>, <professeur>;
//System.out.println("Ridoux <type> <personne>, <professeur>;");
EntityImp Ridoux = new EntityImp("Ridoux");
EntityImp type = new EntityImp("type");
EntityImp personne = new EntityImp("personne");
EntityImp professeur = new EntityImp("professeur");
Complement_EntityImp comple_prof = new Complement_EntityImp(professeur);
Complement_EntityImp comple_pers = new Complement_EntityImp(personne);
AffectationImp aff1 = new AffectationImp(type, List.of(comple_pers, comple_prof));
PhraseImp ph2 = new PhraseImp(Ridoux, List.of(aff1));
//titre
EntityImp titre = new EntityImp("titre");
Complement_TextImp compilation = new Complement_TextImp("Compilation");
AffectationImp aff2 = new AffectationImp(titre, List.of(compilation));
//auteur
EntityImp auteur = new EntityImp("auteur");
EntityImp Ferre = new EntityImp("Ferre");
Complement_EntityImp comple_Ferre = new Complement_EntityImp(Ferre);
Complement_EntityImp comple_Ridoux = new Complement_EntityImp(Ridoux);
AffectationImp aff3 = new AffectationImp(auteur, List.of(comple_Ferre,comple_Ridoux));
//type
EntityImp poly = new EntityImp("poly");
Complement_EntityImp comple_poly = new Complement_EntityImp(poly);
AffectationImp aff4 = new AffectationImp(type, List.of(comple_poly));
//poly117
EntityImp poly117 = new EntityImp("poly117");
PhraseImp ph1 = new PhraseImp(poly117, List.of(aff4, aff3, aff2));
TurtleImp t = new TurtleImp(List.of(ph1, ph2));
System.out.print(t.toString());
} }
/** /**
@@ -24,8 +90,8 @@ public class Main {
* translator. * translator.
* *
* @param args standard arguments passed on the commandline * @param args standard arguments passed on the commandline
* @throws RecognitionException * @throws //RecognitionException
*/ **/
public static void antlrAST(String[] args) throws RecognitionException { public static void antlrAST(String[] args) throws RecognitionException {
try { try {
@@ -57,7 +123,6 @@ public class Main {
throw new RuntimeException("Unable to proceed"); throw new RuntimeException("Unable to proceed");
} }
} }
public static void main(String[] args) throws RecognitionException { public static void main(String[] args) throws RecognitionException {
// Switch between the two fonctions as you make progress // Switch between the two fonctions as you make progress
manualAST(); manualAST();

View File

@@ -1,23 +0,0 @@
package TP1;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenSource;
public class TurtleLexer implements TokenSource {
public TurtleLexer(CharStream input){
}
@Override
public Token nextToken() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'nextToken'");
}
@Override
public String getSourceName() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getSourceName'");
}
}

View File

@@ -1,14 +0,0 @@
package TP1;
import org.antlr.runtime.CommonTokenStream;
public class TurtleParser {
public TurtleParser(CommonTokenStream token){
}
public TurtleAST turtle(){
return null;
}
}