diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 8508ccc..a1d1f19 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -37,57 +37,55 @@ public class Main { CommonTokenStream tokenStream = new CommonTokenStream(lexer); // Printing the tokens - // tokenStream.fill(); - // List tokens = tokenStream.getTokens(); - // System.out.println("-------------------- Scanner -> tokens - // --------------------"); - // for (Token token : tokens) { - // String tokenType = - // SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType()); - // String tokenText = token.getText(); - // // System.out.println("Token Type: " + tokenType + ", Token Text: " + - // // tokenText); - // System.out.println(tokenType + " " + tokenText); - // } - // System.out.println(); + tokenStream.fill(); + List tokens = tokenStream.getTokens(); + System.out.println("-------------------- Scanner -> tokens --------------------"); + for (Token token : tokens) { + String tokenType = + SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType()); + String tokenText = token.getText(); + // System.out.println("Token Type: " + tokenType + ", Token Text: " + + // tokenText); + System.out.println(tokenType + " " + tokenText); + } + System.out.println(); /*------------------------- Parser -> Parsetree -------------------------*/ SimpleJavaParser parser = new SimpleJavaParser(tokenStream); ParseTree parseTree = parser.program(); // parse the input // Printing the parse tree - // System.out.println("-------------------- Parser -> Parsetree - // --------------------"); - // System.out.println(parseTree.toStringTree(parser)); - // printTree(parseTree, parser, 0); - // System.out.println(); + System.out.println("-------------------- Parser -> Parsetree --------------------"); + System.out.println(parseTree.toStringTree(parser)); + printTree(parseTree, parser, 0); + System.out.println(); /*------------------------- AST builder -> AST -------------------------*/ ASTBuilder astBuilder = new ASTBuilder(); ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree); // Printing the AST - // System.out.println("-------------------- AST builder -> AST - // --------------------"); - // // System.out.println("AST: " + ast.toString()); - // printAST(abstractSyntaxTree, 0); - // System.out.println(); + System.out.println("-------------------- AST builder -> AST --------------------"); + // System.out.println("AST: " + ast.toString()); + printAST(abstractSyntaxTree, 0); + System.out.println(); - /*------------------------- Semantic Analyzer -> Tast -------------------------*/ - SemanticAnalyzer.generateTast(abstractSyntaxTree); + /*------------------------- Semantic Analyzer -> typed AST -------------------------*/ ProgramNode typedAst = (ProgramNode) SemanticAnalyzer.generateTast(abstractSyntaxTree); - // Printing the Tast - System.out.println("Tast generated"); + // Printing the typed AST + System.out.println("-------------------- Semantic Analyzer -> typed AST --------------------"); + printAST(typedAst, 0); + System.out.println(); /*------------------------- Bytecode Generator -> Bytecode -------------------------*/ ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(); - // byteCodeGenerator.generateByteCode(abstractSyntaxTree); byteCodeGenerator.visit(typedAst); System.out.println("Bytecode generated"); } + /** * This method is used to print the parse tree in a structured format. * It recursively traverses the tree and prints the rule names and text of the diff --git a/src/main/java/classFileOutput/Example.class b/src/main/java/classFileOutput/Example.class deleted file mode 100644 index 522ae9e..0000000 Binary files a/src/main/java/classFileOutput/Example.class and /dev/null differ diff --git a/src/main/java/classFileOutput/Test.class b/src/main/java/classFileOutput/Test.class deleted file mode 100644 index 8ba4c23..0000000 Binary files a/src/main/java/classFileOutput/Test.class and /dev/null differ diff --git a/src/main/test/java/Tester.java b/src/main/test/java/Tester.java deleted file mode 100644 index 498db7e..0000000 --- a/src/main/test/java/Tester.java +++ /dev/null @@ -1,11 +0,0 @@ -public class Tester { - public static void main(String[] args) { - new EmptyClassExample(); - // cp mitgeben - } -} -// java -jar pfadtocompiler.jar EmptyClass.java -// mit bash scipt ode rmakefile test automatisieren -// mvn package -// javac tester // tester compilen -// java tester // tester ausführen \ No newline at end of file diff --git a/src/main/test/java/EmptyClassExample.java b/src/test/java/EmptyClassExample.java similarity index 100% rename from src/main/test/java/EmptyClassExample.java rename to src/test/java/EmptyClassExample.java diff --git a/src/main/test/TestSpecs.md b/src/test/java/test/TestSpecs.md similarity index 100% rename from src/main/test/TestSpecs.md rename to src/test/java/test/TestSpecs.md diff --git a/src/main/test/java/FailureTest.java b/src/test/java/test/java/FailureTest.java similarity index 100% rename from src/main/test/java/FailureTest.java rename to src/test/java/test/java/FailureTest.java diff --git a/src/main/test/java/MainTest.java b/src/test/java/test/java/MainTest.java similarity index 89% rename from src/main/test/java/MainTest.java rename to src/test/java/test/java/MainTest.java index 516ab6e..9e03dc7 100644 --- a/src/main/test/java/MainTest.java +++ b/src/test/java/test/java/MainTest.java @@ -21,8 +21,8 @@ public class MainTest { void testEmptyClass() { CharStream codeCharStream = null; try { - codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.txt")); - Main.parsefile(codeCharStream); + codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.java")); + Main.parseFile(codeCharStream); } catch (IOException e) { System.err.println("Error reading the file: " + e.getMessage()); } diff --git a/src/test/java/test/java/Tester.java b/src/test/java/test/java/Tester.java new file mode 100644 index 0000000..8890547 --- /dev/null +++ b/src/test/java/test/java/Tester.java @@ -0,0 +1,19 @@ +public class Tester { + public static void main(String[] args) { + // für E2E Tests: + // Testdatei mit Main ausführen/kompilieren + // Testdatei mit "javac CompilerInput.java" kompilieren + + // wenn beides erfolgreich + // Ergebnis vom eigenen Compiler mit "java myOutput" ausführen + // Ergebnis von javac mit "java CompilerInput" ausführen + + + } +} +// cp mitgeben +// java -jar pfadtocompiler.jar EmptyClass.java +// mit bash scipt ode rmakefile test automatisieren +// mvn package +// javac tester // tester compilen +// java tester // tester ausführen \ No newline at end of file diff --git a/src/main/test/java/make.md b/src/test/java/test/java/make.md similarity index 100% rename from src/main/test/java/make.md rename to src/test/java/test/java/make.md diff --git a/src/test/java/semantic/SemanticTest.java b/src/test/java/test/java/semantic/SemanticTest.java similarity index 100% rename from src/test/java/semantic/SemanticTest.java rename to src/test/java/test/java/semantic/SemanticTest.java diff --git a/src/main/test/resources/AllFeaturesClassExample.java b/src/test/resources/AllFeaturesClassExample.java similarity index 100% rename from src/main/test/resources/AllFeaturesClassExample.java rename to src/test/resources/AllFeaturesClassExample.java diff --git a/src/main/test/resources/CombinedExample.java b/src/test/resources/CombinedExample.java similarity index 100% rename from src/main/test/resources/CombinedExample.java rename to src/test/resources/CombinedExample.java diff --git a/src/main/test/resources/CompilerInput.txt b/src/test/resources/CompilerInput.java similarity index 100% rename from src/main/test/resources/CompilerInput.txt rename to src/test/resources/CompilerInput.java diff --git a/src/main/test/resources/MoreFeaturesClassExample.java b/src/test/resources/MoreFeaturesClassExample.java similarity index 100% rename from src/main/test/resources/MoreFeaturesClassExample.java rename to src/test/resources/MoreFeaturesClassExample.java diff --git a/src/main/test/resources/failureTests/TestClass1.java b/src/test/resources/failureTests/TestClass1.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass1.java rename to src/test/resources/failureTests/TestClass1.java diff --git a/src/main/test/resources/failureTests/TestClass10.java b/src/test/resources/failureTests/TestClass10.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass10.java rename to src/test/resources/failureTests/TestClass10.java diff --git a/src/main/test/resources/failureTests/TestClass11.java b/src/test/resources/failureTests/TestClass11.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass11.java rename to src/test/resources/failureTests/TestClass11.java diff --git a/src/main/test/resources/failureTests/TestClass2.java b/src/test/resources/failureTests/TestClass2.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass2.java rename to src/test/resources/failureTests/TestClass2.java diff --git a/src/main/test/resources/failureTests/TestClass3.java b/src/test/resources/failureTests/TestClass3.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass3.java rename to src/test/resources/failureTests/TestClass3.java diff --git a/src/main/test/resources/failureTests/TestClass4.java b/src/test/resources/failureTests/TestClass4.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass4.java rename to src/test/resources/failureTests/TestClass4.java diff --git a/src/main/test/resources/failureTests/TestClass5.java b/src/test/resources/failureTests/TestClass5.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass5.java rename to src/test/resources/failureTests/TestClass5.java diff --git a/src/main/test/resources/failureTests/TestClass6.java b/src/test/resources/failureTests/TestClass6.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass6.java rename to src/test/resources/failureTests/TestClass6.java diff --git a/src/main/test/resources/failureTests/TestClass7.java b/src/test/resources/failureTests/TestClass7.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass7.java rename to src/test/resources/failureTests/TestClass7.java diff --git a/src/main/test/resources/failureTests/TestClass8.java b/src/test/resources/failureTests/TestClass8.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass8.java rename to src/test/resources/failureTests/TestClass8.java diff --git a/src/main/test/resources/failureTests/TestClass9.java b/src/test/resources/failureTests/TestClass9.java similarity index 100% rename from src/main/test/resources/failureTests/TestClass9.java rename to src/test/resources/failureTests/TestClass9.java diff --git a/src/main/test/resources/featureTests/BooleanOperations.java b/src/test/resources/featureTests/BooleanOperations.java similarity index 100% rename from src/main/test/resources/featureTests/BooleanOperations.java rename to src/test/resources/featureTests/BooleanOperations.java diff --git a/src/main/test/resources/featureTests/CharManipulation.java b/src/test/resources/featureTests/CharManipulation.java similarity index 100% rename from src/main/test/resources/featureTests/CharManipulation.java rename to src/test/resources/featureTests/CharManipulation.java diff --git a/src/main/test/resources/featureTests/ConditionalStatements.java b/src/test/resources/featureTests/ConditionalStatements.java similarity index 100% rename from src/main/test/resources/featureTests/ConditionalStatements.java rename to src/test/resources/featureTests/ConditionalStatements.java diff --git a/src/main/test/resources/featureTests/LoopExamples.java b/src/test/resources/featureTests/LoopExamples.java similarity index 100% rename from src/main/test/resources/featureTests/LoopExamples.java rename to src/test/resources/featureTests/LoopExamples.java diff --git a/src/main/test/resources/featureTests/MethodOverloading.java b/src/test/resources/featureTests/MethodOverloading.java similarity index 100% rename from src/main/test/resources/featureTests/MethodOverloading.java rename to src/test/resources/featureTests/MethodOverloading.java