tp1 énoncé traducteur RDF/Turtle vers RDF/Ntriples
This commit is contained in:
17
src/main/antlr/TurtleLexer.g
Normal file
17
src/main/antlr/TurtleLexer.g
Normal 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(); };
|
||||
26
src/main/antlr/TurtleParser.g
Normal file
26
src/main/antlr/TurtleParser.g
Normal 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 ; };
|
||||
64
src/main/java/TP1/Main.java
Normal file
64
src/main/java/TP1/Main.java
Normal 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);
|
||||
}
|
||||
}
|
||||
4
src/main/java/TP1/TurtleASD.java
Normal file
4
src/main/java/TP1/TurtleASD.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package TP1;
|
||||
|
||||
interface TurtleAST {
|
||||
}
|
||||
Reference in New Issue
Block a user