Compare commits

..

No commits in common. "ea97f34398f5412ae514a09d6deb853032b3b38b" and "9b8155ebab61ce6ad53930d7d3035e1ac584f491" have entirely different histories.

7 changed files with 663 additions and 683 deletions

6
.gitignore vendored
View File

@ -77,10 +77,10 @@ fabric.properties
.idea/caches/build_file_checksums.ser .idea/caches/build_file_checksums.ser
/target /target
src/main/resources/logs/miniCompilerLog.log src/main/resources/logs/RaupenLog.log
src/main/resources/output/CompilerInput.class src/main/resources/output/CompilerInput.class
src/test/resources/output/javac/CompilerInput$Test.class src/test/resources/output/javac/CompilerInput$Test.class
src/test/resources/output/javac/CompilerInput.class src/test/resources/output/javac/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput.class src/test/resources/output/raupenpiler/CompilerInput.class
src/test/resources/output/miniCompiler/CompilerInput$Test.class src/test/resources/output/raupenpiler/CompilerInput$Test.class
.idea/inspectionProfiles/Project_Default.xml .idea/inspectionProfiles/Project_Default.xml

View File

@ -1,6 +1,6 @@
# "Nicht Haskel 2.0" Java Compiler # "Nicht Haskel 2.0" Java Compiler
Realisation of a subset of the Java Standard Compiler in the course Compiler Construction of the 4th semester Computer Science at the Duale Hochschule Stuttgart (Horb). Realisation of a subset of the Java Standard Compiler in the course Compiler Construction of the 4th semester Computer Science at the Duale Hochschule Suttgart (Horb).
This project aims to provide a simplified version of the Java compiler, focusing on key language features and demonstrating the principles of compiler construction. This project aims to provide a simplified version of the Java compiler, focusing on key language features and demonstrating the principles of compiler construction.
@ -62,39 +62,7 @@ test/
## How to run the compiler ## How to run the compiler
### Possibilities
### 1. Start miniCompiler using make:
Make needs to be installed
```bash
cd .\src\test\ ; make clean compile-miniCompiler
```
### 2. Start miniCompiler using jar: ## Download
If you do not have the .jar, download it [here](https://gitea.hb.dhbw-stuttgart.de/i22005/NichtHaskell2.0/src/branch/Endabgabe/src) or compile it using mvn package or make first
```
java.exe -DgenJar=bool -DgenClass=bool -jar path_to_jar\jarName.jar 'path_to_input_file.java' 'path_to_output_directory'
```
Example (jar needs to be in the target directory)
```bash
java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'
```
- set DgenJar true, to generate the jar, false for no jar
```
DgenJar=true
```
- set DgenClass true, to generate class files, false for no class files
```
DgenClass=true
```
## How to run tests
```bash ```bash
mvn test
```
Or start them manually in your IDE

View File

@ -17,10 +17,10 @@ import java.util.Optional;
/** /**
* Start miniCompiler using make: * Start Raupenpiler using make:
* <p> <code> cd .\src\test\ </code> * <p> <code> cd .\src\test\ </code>
* <p> <code> make clean compile-miniCompiler </code> * <p> <code> make clean compile-raupenpiler </code>
* <p> Start miniCompiler using jar: * <p> Start Raupenpiler using jar:
* <p> <code> java.exe -DgenJar=true_OR_false -DgenClass=true_OR_false -jar path_to_jar\JavaCompiler-1.0-jar-with-dependencies.jar 'path_to_input_file.java' 'path_to_output_directory' </code> * <p> <code> java.exe -DgenJar=true_OR_false -DgenClass=true_OR_false -jar path_to_jar\JavaCompiler-1.0-jar-with-dependencies.jar 'path_to_input_file.java' 'path_to_output_directory' </code>
* <p> Example (jar needs to be in the target directory, compile with make or mvn package first): * <p> Example (jar needs to be in the target directory, compile with make or mvn package first):
* <code> java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code> * <code> java.exe -DgenJar=true -DgenClass=true -jar .\target\JavaCompiler-1.0-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code>
@ -40,6 +40,16 @@ public class Main {
System.err.println("Error reading the file: " + e.getMessage()); System.err.println("Error reading the file: " + e.getMessage());
} }
} }
/* !!! Else Branch (main ohne args starten) ist nicht zur Verwendung vorgesehen, immer mit args starten !!!
else {
try {
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/main/resources/input/CompilerInput.java"));
compileFile(codeCharStream);
} catch (IOException e) {
System.err.println("Error reading the file: " + e.getMessage());
}
}
*/
} }
/** /**
@ -56,7 +66,7 @@ public class Main {
*/ */
static void compileFile(CharStream inputCharStream, String outputDirectoryPath) { static void compileFile(CharStream inputCharStream, String outputDirectoryPath) {
// Initialize the logger // Initialize the logger
new MiniCompilerLogger(); new RaupenLogger();
/* ------------------------- Scanner -> tokens ------------------------- */ /* ------------------------- Scanner -> tokens ------------------------- */
// Use the SimpleJavaLexer to tokenize the input CharStream // Use the SimpleJavaLexer to tokenize the input CharStream
@ -64,27 +74,27 @@ public class Main {
CommonTokenStream tokenStream = new CommonTokenStream(lexer); CommonTokenStream tokenStream = new CommonTokenStream(lexer);
tokenStream.fill(); tokenStream.fill();
// Log the tokens // Log the tokens
MiniCompilerLogger.logScanner(tokenStream); RaupenLogger.logScanner(tokenStream);
/*------------------------- Parser -> Parsetree -------------------------*/ /*------------------------- Parser -> Parsetree -------------------------*/
// Use the SimpleJavaParser to parse the tokens and generate a ParseTree // Use the SimpleJavaParser to parse the tokens and generate a ParseTree
SimpleJavaParser parser = new SimpleJavaParser(tokenStream); SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program(); // parse the input ParseTree parseTree = parser.program(); // parse the input
// Log the ParseTree // Log the ParseTree
MiniCompilerLogger.logParser(parseTree, parser); RaupenLogger.logParser(parseTree, parser);
/*------------------------- AST builder -> AST -------------------------*/ /*------------------------- AST builder -> AST -------------------------*/
// Use the ASTBuilder to visit the ParseTree and generate an Abstract Syntax Tree (AST) // Use the ASTBuilder to visit the ParseTree and generate an Abstract Syntax Tree (AST)
ASTBuilder astBuilder = new ASTBuilder(); ASTBuilder astBuilder = new ASTBuilder();
ASTNode abstractSyntaxTree = astBuilder.visit(parseTree); ASTNode abstractSyntaxTree = astBuilder.visit(parseTree);
// Log the AST // Log the AST
MiniCompilerLogger.logAST(abstractSyntaxTree); RaupenLogger.logAST(abstractSyntaxTree);
/*------------------------- Semantic Analyzer -> typed AST -------------------------*/ /*------------------------- Semantic Analyzer -> typed AST -------------------------*/
// Use the SemanticAnalyzer to generate a typed AST // Use the SemanticAnalyzer to generate a typed AST
ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree); ASTNode typedAst = SemanticAnalyzer.generateTast(abstractSyntaxTree);
// Log the typed AST // Log the typed AST
MiniCompilerLogger.logSemanticAnalyzer(typedAst); RaupenLogger.logSemanticAnalyzer(typedAst);
if(SemanticAnalyzer.errors.isEmpty()){ if(SemanticAnalyzer.errors.isEmpty()){
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/ /*------------------------- Bytecode Generator -> Bytecode -------------------------*/
@ -97,7 +107,7 @@ public class Main {
assert typedAst != null; assert typedAst != null;
byteCodeGenerator.visit((ProgramNode) typedAst); byteCodeGenerator.visit((ProgramNode) typedAst);
// Log the bytecode generation // Log the bytecode generation
MiniCompilerLogger.logBytecodeGenerator(); RaupenLogger.logBytecodeGenerator();
} else { } else {
for(Exception exception : SemanticAnalyzer.errors){ for(Exception exception : SemanticAnalyzer.errors){
exception.printStackTrace(); exception.printStackTrace();

View File

@ -29,11 +29,11 @@ import java.util.logging.*;
* <code>consoleHandler.setLevel(Level.OFF);</code> * <code>consoleHandler.setLevel(Level.OFF);</code>
* <code>fileHandler.setLevel(Level.ALL);</code> * <code>fileHandler.setLevel(Level.ALL);</code>
*/ */
public class MiniCompilerLogger { public class RaupenLogger {
static Logger logger = Logger.getLogger("miniCompilerLogs"); static Logger logger = Logger.getLogger("RaupenLogs");
public MiniCompilerLogger() { public RaupenLogger() {
// ------------------------- Logging ------------------------- // ------------------------- Logging -------------------------
logger.setLevel(Level.ALL); logger.setLevel(Level.ALL);
logger.getParent().getHandlers()[0].setLevel(Level.ALL); logger.getParent().getHandlers()[0].setLevel(Level.ALL);
@ -66,7 +66,7 @@ public class MiniCompilerLogger {
logger.addHandler(consoleHandler); logger.addHandler(consoleHandler);
// Configure file handler // Configure file handler
Handler fileHandler = new FileHandler("src/main/resources/logs/miniCompiler.log"); Handler fileHandler = new FileHandler("src/main/resources/logs/RaupenLog.log");
// Toggle file logging on/off // Toggle file logging on/off
fileHandler.setLevel(Level.ALL); fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new CustomFormatter()); fileHandler.setFormatter(new CustomFormatter());
@ -117,7 +117,7 @@ public class MiniCompilerLogger {
public static void logBytecodeGenerator() { public static void logBytecodeGenerator() {
// Printing the bytecode // Printing the bytecode
logger.info("-------------------- Bytecode Generator -> Bytecode --------------------"); logger.info("-------------------- Bytecode Generator -> Bytecode --------------------");
logger.info("Bytecode generated without errors."); logger.info("Bytecode generated");
logger.info("\n"); logger.info("\n");
} }

View File

@ -2,17 +2,17 @@
### IntelliJs play buttons do not work. Run in "src/test" folder with "make" command to run all ### IntelliJs play buttons do not work. Run in "src/test" folder with "make" command to run all
### Or run only parts with "make compile-javac", "make clean" etc. ### Or run only parts with "make compile-javac", "make clean" etc.
all: compile-javac compile-miniCompiler all: compile-javac compile-raupenpiler
compile-javac: compile-javac:
javac -d .\resources\output\javac .\resources\input\CompilerInput.java javac -d .\resources\output\javac .\resources\input\CompilerInput.java
compile-miniCompiler: compile-raupenpiler:
cd ../.. ; mvn -DskipTests install cd ../.. ; mvn -DskipTests install
cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'" cd ../.. ; mvn exec:java -DgenJar=true -DgenClass=true -Dexec.mainClass="main.Main" -Dexec.args="'src/main/resources/input/CompilerInput.java' 'src/main/resources/output'"
# cp ../main/resources/output/CompilerInput.class .java/resources/output/miniCompiler # cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler
test-miniCompiler: test-raupenpiler:
# move the compiled class to the test/main folder # move the compiled class to the test/main folder
mv ../main/resources/output/CompilerInput.class .java/main/ mv ../main/resources/output/CompilerInput.class .java/main/
# compile the test class # compile the test class
@ -28,8 +28,8 @@ clean:
rm -f ../main/resources/output/*.jar rm -f ../main/resources/output/*.jar
# clean resources output folders # clean resources output folders
rm -f ./resources/output/javac/*.class rm -f ./resources/output/javac/*.class
rm -f ./resources/output/miniCompiler/*.class rm -f ./resources/output/raupenpiler/*.class
rm -f ./resources/output/miniCompiler/*.jar rm -f ./resources/output/raupenpiler/*.jar
# clean logs # clean logs
rm -f ../main/resources/logs/* rm -f ../main/resources/logs/*
# clean test/java/main folders from .class files for End-to-End tests # clean test/java/main folders from .class files for End-to-End tests

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,8 @@ package main;
* Wenn unser Compiler funktioniert, sollten keine Errors kommen (sondern nur die Ausgaben, die wir in der CompilerInput.java Datei gemacht haben, * Wenn unser Compiler funktioniert, sollten keine Errors kommen (sondern nur die Ausgaben, die wir in der CompilerInput.java Datei gemacht haben,
* oder Methoden, die wir hier aufrufen).</p> * oder Methoden, die wir hier aufrufen).</p>
* *
* <p><strong>PROBLEM:</strong> Hier kommen Errors, was eigentlich heißt, dass der Compiler nicht funktioniert, der Test sollte eigentlich passen.
* <br><strong>DENN:</strong> Wenn ich statt unserem CompilerInput.class die CompilerInput.class von javac verwende (aus <code> src/test/resources/output/javac </code>), dann funktioniert es.</p>
*/ */
public class EndToEndTester { public class EndToEndTester {
public static void main(String[] args) { public static void main(String[] args) {