diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..aa00ffa
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 80b387d..aec221f 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -24,7 +24,7 @@
-
-
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index 0b5faa7..d69702e 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -3,7 +3,6 @@
-
\ No newline at end of file
diff --git a/NichtHaskell.iml b/NichtHaskell.iml
index 2e9d176..fbfe57d 100644
--- a/NichtHaskell.iml
+++ b/NichtHaskell.iml
@@ -2,7 +2,10 @@
-
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index ddaf6e1..685dd23 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,25 +4,45 @@
4.0.0
Clippit.org
NichtHaskell
- 1
+ 1.0-SNAPSHOT
- 20
- 20
+ 22
+ 22
+ 22
+ UTF-8
-
+ ${project.artifactId}
org.apache.maven.plugins
- maven-surefire-plugin
- 2.22.2
+ maven-assembly-plugin
+ 3.7.1
+
+
+
+ Compiler
+
+
+
+ jar-with-dependencies
+
+
+
+
+ make-assembly
+ package
+
+ single
+
+
+
-
junit
diff --git a/src/main/java/Compiler.java b/src/main/java/Compiler.java
index 28b873d..d1b8163 100644
--- a/src/main/java/Compiler.java
+++ b/src/main/java/Compiler.java
@@ -1,4 +1,4 @@
-import abstractSyntaxTree.Class.RefType;
+import TypeCheck.TypeCheckException;
import abstractSyntaxTree.Program;
import astGenerator.ASTGenerator;
import gen.DecafLexer;
@@ -18,41 +18,54 @@ public class Compiler {
public static void main(String[] args) throws Exception{
- Path filePath = Paths.get("src/main/java/TestClass.java");
+ // todo code für jar
+// if (args.length < 1) {
+// System.out.println("Usage: java -jar Compiler.jar [--suppress-details]");
+// return;
+// }
+ //String filePath = args[0];
+ String filePath = "src/main/java/TestClass.java";
+ // TODO false setzen für jar-Build
+ boolean suppressDetails = true;
- // todo remove this debug info
- Path absolutePath = filePath.toAbsolutePath();
- System.out.println("Processing input: " + absolutePath);
+ if (args.length > 1 && args[1].equals("--suppress-details")) {
+ suppressDetails = true;
+ }
- String content;
- try {
- content = Files.readString(filePath);
- }catch (java.nio.file.NoSuchFileException e){
- System.out.println("File not found");
+ Path path = Paths.get(filePath);
+
+ if (!Files.exists(path)) {
+ System.out.println("Your input file was not found: " + path);
return;
}
+ if(!suppressDetails)
+ System.out.println("Processing input: " + path);
- System.out.println("--- print content ---");
- System.out.println(content);
+ String content = Files.readString(path);
+
+ if(!suppressDetails)
+ System.out.println("The content of your input file is: \n" + content);
CharStream codeCharStream = CharStreams.fromString(content);
DecafLexer lexer = new DecafLexer(codeCharStream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
- System.out.println("--- print tokens ---");
tokens.fill();
- List tokenList = tokens.getTokens();
+ if(!suppressDetails) {
- StringBuilder stringBuilder = new StringBuilder();
- for (Token token : tokenList) {
- stringBuilder.append(token.getText()).append(" ");
+ List tokenList = tokens.getTokens();
+
+ StringBuilder stringBuilder = new StringBuilder();
+ for (Token token : tokenList) {
+ stringBuilder.append(token.getText()).append(" ");
+ }
+ String readableTokens = stringBuilder.toString().trim();
+
+ System.out.println("The tokens of your input are: \n" + readableTokens);
}
- String readableTokens = stringBuilder.toString().trim();
-
- System.out.println(readableTokens);
DecafParser parser = new DecafParser(tokens);
@@ -63,14 +76,30 @@ public class Compiler {
Program abstractSyntaxTree =(Program) generator.visit(tree);
- System.out.println("--- AST generator ---");
- System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes with names:");
- for (RefType refType : abstractSyntaxTree.classes) {
- System.out.println(refType.name);
- }
+ 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();
+ }
+ });
+ }
+// try {
+// abstractSyntaxTree.typeCheck();
+// }catch(TypeCheckException e){
+// System.out.println("A TypeCheck error occurred. The compilation was stopped.");
+// System.out.println(e);
+// return;
+// }
abstractSyntaxTree.typeCheck();
+ if(!suppressDetails)
+ System.out.println("No TypeCheck errors found.");
abstractSyntaxTree.codeGen();
+ System.out.println("Your input was compiler. You can find the output at ???");// todo wo output? überhaupt hinschreiben?
}
}
diff --git a/src/main/java/Input.java b/src/main/java/Input.java
index e1baa5f..31cf09b 100644
--- a/src/main/java/Input.java
+++ b/src/main/java/Input.java
@@ -1,4 +1,4 @@
-class Example1 {
+class Example1b {
public int fak(int number){
if(number < 0){
return 1;
diff --git a/src/main/java/TestClass.java b/src/main/java/TestClass.java
index f21bd45..55a283e 100644
--- a/src/main/java/TestClass.java
+++ b/src/main/java/TestClass.java
@@ -1,5 +1,27 @@
-public class TestClass {
- public static void main(String[] args){
+class TestClass {
+ int i;
+ int a = 12345;
+ Example e;
+ public TestClass(){i = 3456;}
+ int meth(int n){
+ Example e = new Example();
+ int abc = e.example1.m1(2).m2().m3();
+ return 0;
+ }
+ Example m1(int n){
+ return new Example();
}
}
+
+class Example {
+ int i;
+ boolean b;
+ char c;
+ TestClass example1;
+ TestClass m(int a){
+ return new TestClass();
+ }
+ Example m2(){return new Example();}
+ int m3(){return 1;}
+}
\ No newline at end of file