From 2a20a91d35e1fe856c13eb406c37dcb2bb573a1b Mon Sep 17 00:00:00 2001 From: Lucas <89882946+notbad3500@users.noreply.github.com> Date: Fri, 31 May 2024 10:55:41 +0200 Subject: [PATCH] Refactor structure and more --- src/main/java/Main.java | 54 +++++++++--------- src/main/java/classFileOutput/Example.class | Bin 167 -> 0 bytes src/main/java/classFileOutput/Test.class | Bin 97 -> 0 bytes src/main/test/java/Tester.java | 11 ---- .../test/java/EmptyClassExample.java | 0 src/{main => test/java}/test/TestSpecs.md | 0 .../java}/test/java/FailureTest.java | 0 .../java}/test/java/MainTest.java | 4 +- src/test/java/test/java/Tester.java | 19 ++++++ src/{main => test/java}/test/java/make.md | 0 .../java}/semantic/SemanticTest.java | 0 .../resources/AllFeaturesClassExample.java | 0 .../test/resources/CombinedExample.java | 0 .../resources/CompilerInput.java} | 0 .../resources/MoreFeaturesClassExample.java | 0 .../resources/failureTests/TestClass1.java | 0 .../resources/failureTests/TestClass10.java | 0 .../resources/failureTests/TestClass11.java | 0 .../resources/failureTests/TestClass2.java | 0 .../resources/failureTests/TestClass3.java | 0 .../resources/failureTests/TestClass4.java | 0 .../resources/failureTests/TestClass5.java | 0 .../resources/failureTests/TestClass6.java | 0 .../resources/failureTests/TestClass7.java | 0 .../resources/failureTests/TestClass8.java | 0 .../resources/failureTests/TestClass9.java | 0 .../featureTests/BooleanOperations.java | 0 .../featureTests/CharManipulation.java | 0 .../featureTests/ConditionalStatements.java | 0 .../resources/featureTests/LoopExamples.java | 0 .../featureTests/MethodOverloading.java | 0 31 files changed, 47 insertions(+), 41 deletions(-) delete mode 100644 src/main/java/classFileOutput/Example.class delete mode 100644 src/main/java/classFileOutput/Test.class delete mode 100644 src/main/test/java/Tester.java rename src/{main => }/test/java/EmptyClassExample.java (100%) rename src/{main => test/java}/test/TestSpecs.md (100%) rename src/{main => test/java}/test/java/FailureTest.java (100%) rename src/{main => test/java}/test/java/MainTest.java (89%) create mode 100644 src/test/java/test/java/Tester.java rename src/{main => test/java}/test/java/make.md (100%) rename src/test/java/{ => test/java}/semantic/SemanticTest.java (100%) rename src/{main => }/test/resources/AllFeaturesClassExample.java (100%) rename src/{main => }/test/resources/CombinedExample.java (100%) rename src/{main/test/resources/CompilerInput.txt => test/resources/CompilerInput.java} (100%) rename src/{main => }/test/resources/MoreFeaturesClassExample.java (100%) rename src/{main => }/test/resources/failureTests/TestClass1.java (100%) rename src/{main => }/test/resources/failureTests/TestClass10.java (100%) rename src/{main => }/test/resources/failureTests/TestClass11.java (100%) rename src/{main => }/test/resources/failureTests/TestClass2.java (100%) rename src/{main => }/test/resources/failureTests/TestClass3.java (100%) rename src/{main => }/test/resources/failureTests/TestClass4.java (100%) rename src/{main => }/test/resources/failureTests/TestClass5.java (100%) rename src/{main => }/test/resources/failureTests/TestClass6.java (100%) rename src/{main => }/test/resources/failureTests/TestClass7.java (100%) rename src/{main => }/test/resources/failureTests/TestClass8.java (100%) rename src/{main => }/test/resources/failureTests/TestClass9.java (100%) rename src/{main => }/test/resources/featureTests/BooleanOperations.java (100%) rename src/{main => }/test/resources/featureTests/CharManipulation.java (100%) rename src/{main => }/test/resources/featureTests/ConditionalStatements.java (100%) rename src/{main => }/test/resources/featureTests/LoopExamples.java (100%) rename src/{main => }/test/resources/featureTests/MethodOverloading.java (100%) 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 522ae9edd25429b756d2dd98d755bdedb11f81c3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 167 zcmW-Z%?`m(5QV>?KU4{C(b_cjVj~t^h@Jh#4Q;BGxDl^qC9&`T9!g9t=FB(eoXqF@ zdIK{?Lb$q{^QE#OB8*FOGg)QoW476qcJD&ELNG7t!Yzbul5S&sf(VaL5Tla|k+WB~ uw(is%1V731R84Q$94tadyXY4BL`oeceW5zkYw}OPpFZh5)M%>%;ue1AIvEN8 diff --git a/src/main/java/classFileOutput/Test.class b/src/main/java/classFileOutput/Test.class deleted file mode 100644 index 8ba4c23343d79136e322bf6f22591360f6985b92..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 97 zcmX^0Z`VEs1_l!bPDTcnkksN5b_Pa927#=^vPAuy#JqHU|D>$cWS}TBBLkaFW?p8A m9U}v?hGrO0c?nQCBTzFV0}}%am}X>PXW)RcSQ*%WECv8I3=j$c 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