tp1 énoncé traducteur RDF/Turtle vers RDF/Ntriples

This commit is contained in:
Delphine Demange
2025-01-17 07:28:54 +01:00
commit ea75c0e0ba
16 changed files with 887 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
lexer grammar TurtleLexer;
options {
language = Java;
}
@header {
package TP1;
}
@members {
}
// Whitespaces are ignored.
fragment WS: (' ' | '\n' | '\t' | '\r' | '\u000C');
WSS: WS+ { skip(); };

View File

@@ -0,0 +1,26 @@
parser grammar TurtleParser;
options {
language = Java;
tokenVocab = TurtleLexer;
k = 1;
}
@header {
package TP1;
}
// On syntax error, raise exception rather than silently recovery
@rulecatch {
catch (RecognitionException e) {
reportError(e) ;
throw(e) ;
}
}
@members {
}
turtle
returns[TurtleAST t]: EOF { $t = null ; };

View File

@@ -0,0 +1,64 @@
package TP1;
import java.io.IOException;
import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.ANTLRInputStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
public class Main {
/**
* Buils example AST and illustrates the translator.
*/
public static void manualAST() {
System.out.println("Traducteur à compléter !");
}
/**
* Builds AST from text files, using lexer and parser and illustrates the
* translator.
*
* @param args standard arguments passed on the commandline
* @throws RecognitionException
*/
public static void antlrAST(String[] args) throws RecognitionException {
try {
// Set input
CharStream input;
if (args.length == 0) {
// From standard input
input = new ANTLRInputStream(System.in);
} else {
// From file name in first argument
input = new ANTLRFileStream(args[0]);
}
// Instantiate Lexer
TurtleLexer lexer = new TurtleLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Instantiate Parser
TurtleParser parser = new TurtleParser(tokens);
// Parse
TurtleAST t = parser.turtle();
// Use the AST next
System.out.println(t);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unable to proceed");
}
}
public static void main(String[] args) throws RecognitionException {
// Switch between the two fonctions as you make progress
manualAST();
// antlrAST(args);
}
}

View File

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