Structure, Makefile, Docs, TestCompilerOutput, more; TODO: fix marked Problems in Makefile; fix Compiler (look at TestCompilerOutput docs)
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled
This commit is contained in:
parent
9f40949f5a
commit
8d6190b130
4
pom.xml
4
pom.xml
@ -9,8 +9,8 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
<maven.compiler.target>21</maven.compiler.target>
|
||||
<maven.compiler.source>22</maven.compiler.source>
|
||||
<maven.compiler.target>22</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
@ -1,18 +1,14 @@
|
||||
import ast.ASTNode;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import ast.ProgramNode;
|
||||
import bytecode.ByteCodeGenerator;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import parser.ASTBuilder;
|
||||
import parser.generated.SimpleJavaLexer;
|
||||
import parser.generated.SimpleJavaParser;
|
||||
import semantic.SemanticAnalyzer;
|
||||
import bytecode.ByteCodeGenerator;
|
||||
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
@ -20,7 +16,7 @@ import java.util.List;
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length > 0) {
|
||||
|
||||
System.out.println("Main file has args: " + args[0]);
|
||||
} else {
|
||||
try {
|
||||
CharStream codeCharStream = CharStreams.fromPath(Paths.get("src/main/resources/CompilerInput.java"));
|
||||
|
@ -52,7 +52,7 @@ public class ClassCodeGen implements ClassVisitor {
|
||||
}
|
||||
|
||||
private void printIntoClassFile(byte[] byteCode, String name) {
|
||||
String directoryPath = "src/main/java/classFileOutput";
|
||||
String directoryPath = "src/main/resources/classFileOutput";
|
||||
File directory = new File(directoryPath);
|
||||
if (!directory.exists()) {
|
||||
directory.mkdirs();
|
||||
|
@ -1,18 +1,16 @@
|
||||
public class Example {
|
||||
public class CompilerInput {
|
||||
|
||||
public int a;
|
||||
|
||||
public static int testMethod(char x){
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public class Test {
|
||||
|
||||
public static int testMethod(char x, int a){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
24
src/test/Makefile
Normal file
24
src/test/Makefile
Normal file
@ -0,0 +1,24 @@
|
||||
# Makefile
|
||||
### 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 delete" etc.
|
||||
|
||||
all: delete compile-javac compile-raupenpiler
|
||||
|
||||
compile-javac:
|
||||
javac -d .\resources\output\javac .\resources\CompilerInput.java
|
||||
|
||||
compile-raupenpiler:
|
||||
## funktioniert bisher nicht, das will die Klasse nicht laden, der traditionelle Weg findet externe Libraries (antlr) nicht, maven hat andere Probleme
|
||||
## Unseren Compiler also erstmal händisch starten: main.java/Main.java
|
||||
#javac -d ./resources/output/raupenpiler -cp ../main/java;../../.lib/antlr-4.12.0-complete.jar ../main/java/Main.java
|
||||
#java -cp ./resources/output/raupenpiler Main
|
||||
#mvn -f ../../ compile
|
||||
#mvn -f ../../ exec:java -Dexec.mainClass="Main"
|
||||
|
||||
delete:
|
||||
rm -f ./resources/output/javac/*.class
|
||||
rm -f ./resources/output/raupenpiler/*.class
|
||||
rm -f ./java/*.class
|
||||
rm -f ../main/resources/classFileOutput/*.class
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Scanner
|
||||
|
||||
## Scanner Input
|
||||
|
||||
### Beispiel 1: Empty Class
|
||||
|
||||
String empty class = "public class Name {}";
|
||||
@ -15,6 +17,7 @@
|
||||
"}"
|
||||
|
||||
## Scanner Output
|
||||
|
||||
### Beispiel 1: Empty Class
|
||||
|
||||
Token Type; Token Text
|
||||
@ -35,52 +38,62 @@ Type gibts nur bei Terminalen, Text bei allen
|
||||
[TokRightBrace]
|
||||
|
||||
# Parser
|
||||
|
||||
## Parser Input
|
||||
|
||||
(Scanner Output)
|
||||
|
||||
## Parser Output (AST)
|
||||
|
||||
### Beispiel 1: Empty Class
|
||||
|
||||
|
||||
|
||||
### Beispiel 2: Filled Class
|
||||
|
||||
|
||||
|
||||
# Semantische Analyse / Typcheck
|
||||
|
||||
## Typcheck Input
|
||||
|
||||
(Parser Output = AST)
|
||||
|
||||
## Typcheck Output
|
||||
|
||||
### Beispiel 1: Empty Class
|
||||
|
||||
|
||||
|
||||
### Beispiel 2: Filled Class
|
||||
|
||||
|
||||
# Bytecodegenerierung
|
||||
|
||||
## Bytecodegenerierung Input
|
||||
|
||||
(Typcheck Output = vom Typcheck eventuell manipulierter AST)
|
||||
|
||||
## Bytecodegenerierung Output
|
||||
|
||||
### Beispiel 1: Empty Class
|
||||
|
||||
Compiled Classfile
|
||||
|
||||
public class javaFileInput.Example {
|
||||
}
|
||||
|
||||
|
||||
|
||||
### Beispiel 2: Filled Class
|
||||
|
||||
## E2E Tests:
|
||||
|
||||
für E2E Tests:
|
||||
Testdatei mit Main ausführen/kompilieren
|
||||
Testdatei mit "javac CompilerInput.java" kompilieren
|
||||
- Testdatei mit Main ausführen/kompilieren
|
||||
- Testdatei mit "javac -d output .\CompilerInput.java" kompilieren
|
||||
- -> Dateien mit javap vergleichen
|
||||
|
||||
wenn beides erfolgreich
|
||||
Ergebnis vom eigenen Compiler mit "java myOutput" ausführen
|
||||
Ergebnis von javac mit "java CompilerInput" ausführen
|
||||
- Ergebnis vom eigenen Compiler mithilfe von TestCompilerOutput ausführen
|
||||
- (Ergebnis von javac mithilfe von TestCompilerOutput ausführen)
|
||||
|
||||
|
||||
### Andis Tipps:
|
||||
- cp mitgeben
|
||||
- makefile
|
||||
- java -jar pfadtocompiler.jar EmptyClass.java
|
||||
- mvn package
|
||||
- javac tester // tester compilen
|
||||
- java tester // tester ausführen
|
||||
- -> tester ist in unserem Fall TestCompilerOutput.java
|
41
src/test/java/TestCompilerOutput.java
Normal file
41
src/test/java/TestCompilerOutput.java
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* This class is used to test the output of the compiler.
|
||||
* <p>
|
||||
* Im gleichen Ordner wie die diese Datei (TestCompilerOutput.java) muss die selbstkompilierte CompilerInput.java Datei sein.
|
||||
* --->>>> Diese muss man also vom Ordner classFileOutput in diesen ordner hier (test/java) rein kopieren. (bis es eine bessere Lösung gibt) <<<<---
|
||||
* Die selbstkompilierte .class Datei wird dann hier drin geladen und eine Instanz von ihr erstellt, es können auch Methoden aufgerufen werden.
|
||||
* Diese TestCompilerOutput.java Datei wird dann mit "javac .\TestCompilerOutput.java" kompiliert und mit "java TestCompilerOutput" ausgeführt.
|
||||
* 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).
|
||||
* PROBLEM: hier kommen errors, was eigentlich heißt, dass der Compiler nicht funktioniert, der der Test sollt eigentlich passen
|
||||
*/
|
||||
public class TestCompilerOutput {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Try to load the class named "CompilerInput"
|
||||
Class<?> cls = Class.forName("CompilerInput");
|
||||
// Print a success message if the class is loaded successfully
|
||||
System.out.println("Class loaded successfully: " + cls.getName());
|
||||
|
||||
// Try to create an instance of the loaded class
|
||||
Object instance = cls.getDeclaredConstructor().newInstance();
|
||||
// Print a success message if the instance is created successfully
|
||||
System.out.println("Instance created: " + instance);
|
||||
|
||||
|
||||
// If the class has a main method, you can invoke it
|
||||
// cls.getMethod("main", String[].class).invoke(null, (Object) new String[]{});
|
||||
|
||||
// If the class has other methods, you can invoke them as well
|
||||
// Example: cls.getMethod("someMethod").invoke(instance);
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Print an error message if the class is not found
|
||||
System.err.println("Class not found: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
// Print an error message if any other exception occurs during class loading or instance creation
|
||||
System.err.println("Error during class loading or execution: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
public class Tester {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
// 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
|
@ -1,13 +1,9 @@
|
||||
public class Example {
|
||||
|
||||
public int testVar;
|
||||
|
||||
public static int testMethod(char b){
|
||||
|
||||
int a;
|
||||
int a;
|
||||
public class CompilerInput {
|
||||
|
||||
public int a;
|
||||
|
||||
public static int testMethod(char x){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user