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.tree.ParseTree;
|
||||
|
||||
import java.io.Console;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -18,16 +19,15 @@ public class Compiler {
|
||||
|
||||
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];
|
||||
String filePath = "src/main/java/TestClass.java";
|
||||
// TODO false setzen für jar-Build
|
||||
boolean suppressDetails = true;
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage: java -jar Compiler.jar <file_path> [--suppress-details]");
|
||||
return;
|
||||
}
|
||||
|
||||
String filePath = args[0];
|
||||
|
||||
boolean suppressDetails = false;
|
||||
|
||||
if (args.length > 1 && args[1].equals("--suppress-details")) {
|
||||
suppressDetails = true;
|
||||
@ -64,7 +64,7 @@ public class Compiler {
|
||||
}
|
||||
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) {
|
||||
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes: ");
|
||||
abstractSyntaxTree.classes.forEach(refType -> {
|
||||
System.out.print(refType.name);
|
||||
if (abstractSyntaxTree.classes.indexOf(refType) < abstractSyntaxTree.classes.size() - 1) {
|
||||
System.out.print(", ");
|
||||
} else {
|
||||
System.out.println("\t" + refType.name);
|
||||
});
|
||||
System.out.println();
|
||||
}
|
||||
});
|
||||
}
|
||||
// try {
|
||||
// abstractSyntaxTree.typeCheck();
|
||||
// }catch(TypeCheckException e){
|
||||
// System.out.println("A TypeCheck error occurred. The compilation was stopped.");
|
||||
// System.out.println(e);
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
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)
|
||||
System.out.println("No TypeCheck errors found.");
|
||||
|
||||
try {
|
||||
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