save before apply thing from l3

This commit is contained in:
tuvu
2025-02-13 23:58:00 +01:00
3 changed files with 67 additions and 15 deletions

View File

@@ -22,6 +22,7 @@ options {
}
prog : bloc EOF
{$t = new TurtleAST()}
;
bloc : sujet listvc P manyb // <entity> list.
;

View File

@@ -1,8 +1,63 @@
package TP1;
public class TurtleAST {
public TurtleAST(){
import java.util.ArrayList;
import java.util.List;
public class TurtleAST {
sealed interface Ntriple{}
sealed interface Phrase{}
sealed interface Entity{}
record NtripleImp(List<PhraseImp> phrases) implements Ntriple{
public String toString(){
String str = "";
for (PhraseImp phrase : this.phrases) {
str += phrase.toString() + ".\n" ;
}
return str;
}
}
record PhraseImp(EntityImp s, EntityImp v, EntityImp c) implements Phrase{
public String toString(){
return s.toString() + " " + v.toString() + " " + c.toString();
}
}
record EntityImp(String val, Boolean isText) implements Entity{
public String toString(){
String str="";
if(isText) str = "\"" + val + "\"";
else str = "<" + val + ">";
return str;
}
}
String currentSujet;
String currentVerbe;
List<PhraseImp> listPhrases;
Ntriple ntriple;
public TurtleAST(){
this.listPhrases = new ArrayList<>();
}
public void addSujet(String sujet){
this.currentSujet=sujet;
}
public void addVerbe(String verbe){
this.currentVerbe=verbe;
}
public void addComplement(String complement, Boolean isText){
EntityImp s = new EntityImp(currentSujet, false);
EntityImp v = new EntityImp(currentVerbe, false);
EntityImp c = new EntityImp(complement, isText);
PhraseImp phrase = new PhraseImp(s,v,c);
this.listPhrases.add(phrase);
}
public void finishNtriple(){
this.ntriple = new NtripleImp(listPhrases);
}
}