Files
tp2-vsl-pds/src/main/java/TP2/Main.java

69 lines
1.7 KiB
Java

package TP2;
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;
import org.antlr.runtime.Token;
import TP2.asd.Program.*;
import TP2.llvm.ProgramLLVM;
import TP2.llvm.ProgramLLVM.*;
import java.util.*;
/*
./gradlew build
java -jar build/libs/TP2.jar tests/fragment0/priority2.vsl
*/
public class Main {
public static void main(String[] args) {
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
VSLLexer lexer = new VSLLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Instantiate Parser
VSLParser parser = new VSLParser(tokens);
// Parse
ProgramImp ast = parser.program();
// Pretty-print the program (to debug parsing)
System.err.println("todo " + ast);
System.out.println("\n\n PRETTYPRINTER VSK : \n--------------\n" + ast.prettyprinter() + "\n--------------\nFIN PRETTYPRINTER");
// Verify the program semantic
// Generate the intermediate representation
System.out.println("todo");
ProgramLLVMImpl astLLVM = ast.toLLVM();
System.out.println("\n\n PRETTYPRINTER LLBD : \n--------------\n" + astLLVM.prettyprinter() + "\n--------------\nFIN PRETTYPRINTER");
} catch (IOException | RecognitionException e) {
e.printStackTrace();
throw new RuntimeException("Unable to proceed");
}
}
}