compiler code for jar
This commit is contained in:
parent
6948797001
commit
c9ce9e02db
@ -9,6 +9,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
|||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
|
|
||||||
|
import java.io.Console;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@ -18,16 +19,15 @@ public class Compiler {
|
|||||||
|
|
||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args) throws Exception{
|
||||||
|
|
||||||
// todo code für jar
|
|
||||||
// if (args.length < 1) {
|
|
||||||
// System.out.println("Usage: java -jar Compiler.jar <file_path> [--suppress-details]");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//String filePath = args[0];
|
if (args.length < 1) {
|
||||||
String filePath = "src/main/java/TestClass.java";
|
System.out.println("Usage: java -jar Compiler.jar <file_path> [--suppress-details]");
|
||||||
// TODO false setzen für jar-Build
|
return;
|
||||||
boolean suppressDetails = true;
|
}
|
||||||
|
|
||||||
|
String filePath = args[0];
|
||||||
|
|
||||||
|
boolean suppressDetails = false;
|
||||||
|
|
||||||
if (args.length > 1 && args[1].equals("--suppress-details")) {
|
if (args.length > 1 && args[1].equals("--suppress-details")) {
|
||||||
suppressDetails = true;
|
suppressDetails = true;
|
||||||
@ -64,7 +64,7 @@ public class Compiler {
|
|||||||
}
|
}
|
||||||
String readableTokens = stringBuilder.toString().trim();
|
String readableTokens = stringBuilder.toString().trim();
|
||||||
|
|
||||||
System.out.println("The tokens of your input are: \n" + readableTokens);
|
System.out.println("The tokens of your input are: \n" + readableTokens + "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,26 +80,31 @@ public class Compiler {
|
|||||||
if(!suppressDetails) {
|
if(!suppressDetails) {
|
||||||
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes: ");
|
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes: ");
|
||||||
abstractSyntaxTree.classes.forEach(refType -> {
|
abstractSyntaxTree.classes.forEach(refType -> {
|
||||||
System.out.print(refType.name);
|
System.out.println("\t" + refType.name);
|
||||||
if (abstractSyntaxTree.classes.indexOf(refType) < abstractSyntaxTree.classes.size() - 1) {
|
});
|
||||||
System.out.print(", ");
|
|
||||||
} else {
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
try {
|
||||||
// try {
|
|
||||||
// abstractSyntaxTree.typeCheck();
|
|
||||||
// }catch(TypeCheckException e){
|
|
||||||
// System.out.println("A TypeCheck error occurred. The compilation was stopped.");
|
|
||||||
// System.out.println(e);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
abstractSyntaxTree.typeCheck();
|
abstractSyntaxTree.typeCheck();
|
||||||
|
}catch(TypeCheckException e){
|
||||||
|
System.out.println("A TypeCheck error was found in you input. Your input was not compiled.");
|
||||||
|
System.out.println(e);
|
||||||
|
return;
|
||||||
|
}catch (Exception e){
|
||||||
|
System.out.println("A unexpected error occurred in TypeCheck.");
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
|
||||||
if(!suppressDetails)
|
if(!suppressDetails)
|
||||||
System.out.println("No TypeCheck errors found.");
|
System.out.println("No TypeCheck errors found.");
|
||||||
|
|
||||||
|
try {
|
||||||
abstractSyntaxTree.codeGen();
|
abstractSyntaxTree.codeGen();
|
||||||
System.out.println("Your input was compiled. You can find the output at ???");// todo wo output? überhaupt hinschreiben?
|
}catch (Exception e){
|
||||||
|
System.out.println("A error occurred during code generation. Your input was not compiled.");
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
System.out.println("Your input was compiled. You can find the output in your current working directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user