Small changes
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
8cc67080ec
commit
b37e065857
@ -3,9 +3,6 @@ package ast;
|
||||
//import java.util.List;
|
||||
|
||||
public interface ASTNode {
|
||||
/**
|
||||
* Please implement this method to return a list of children of each node.
|
||||
*/
|
||||
// public List<ASTNode> getChildren();
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,7 @@ public class MethodNode implements MemberNode, Visitable {
|
||||
|
||||
public List<StatementNode> statements = new ArrayList<>();
|
||||
|
||||
public MethodNode(AccessTypeNode visibility, TypeNode type, String identifier, ParameterListNode parameters,
|
||||
List<StatementNode> statements){
|
||||
public MethodNode(AccessTypeNode visibility, TypeNode type, String identifier, ParameterListNode parameters, List<StatementNode> statements) {
|
||||
this.visibility = visibility;
|
||||
this.type = type;
|
||||
this.identifier = identifier;
|
||||
@ -31,18 +30,18 @@ public class MethodNode implements MemberNode, Visitable {
|
||||
this.statements = statements;
|
||||
}
|
||||
|
||||
public MethodNode(AccessTypeNode visibility, String identifier){
|
||||
public MethodNode(AccessTypeNode visibility, String identifier) {
|
||||
this.visibility = visibility;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public boolean isSame(MethodNode methodNode){
|
||||
public boolean isSame(MethodNode methodNode) {
|
||||
boolean isSame = false;
|
||||
if(methodNode.identifier.equals(identifier)){
|
||||
if(parameters != null && methodNode.parameters != null){
|
||||
if(parameters.parameters.size() == methodNode.parameters.parameters.size()){
|
||||
for(int i = 0; i < parameters.parameters.size(); i++){
|
||||
if(parameters.parameters.get(i).identifier.equals(methodNode.parameters.parameters.get(i).identifier)){
|
||||
if (methodNode.identifier.equals(identifier)) {
|
||||
if (parameters != null && methodNode.parameters != null) {
|
||||
if (parameters.parameters.size() == methodNode.parameters.parameters.size()) {
|
||||
for (int i = 0; i < parameters.parameters.size(); i++) {
|
||||
if (parameters.parameters.get(i).identifier.equals(methodNode.parameters.parameters.get(i).identifier)) {
|
||||
isSame = true;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,10 @@
|
||||
package main;
|
||||
|
||||
import ast.ASTNode;
|
||||
import ast.ClassNode;
|
||||
import ast.ProgramNode;
|
||||
import ast.type.AccessTypeNode;
|
||||
import ast.type.EnumAccessTypeNode;
|
||||
import parser.ASTBuilder;
|
||||
import parser.generated.SimpleJavaLexer;
|
||||
import parser.generated.SimpleJavaParser;
|
||||
@ -25,8 +28,6 @@ import java.nio.file.Paths;
|
||||
* <code> java.exe -jar .\target\JavaCompiler-1.0-SNAPSHOT-jar-with-dependencies.jar 'src/main/resources/input/CompilerInput.java' 'src/main/resources/output' </code>
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length == 2) {
|
||||
// args[0] is the input file path
|
||||
|
@ -16,18 +16,18 @@ import java.util.List;
|
||||
import java.util.logging.*;
|
||||
|
||||
/**
|
||||
Beispiel für Logging-Arten:
|
||||
<p><code>logger.severe("Schwerwiegender Fehler");</code>
|
||||
<p><code>logger.warning("Warnung");</code>
|
||||
<p><code>logger.info("Information");</code>
|
||||
<p><code>logger.config("Konfigurationshinweis");</code>
|
||||
<p><code>logger.fine("Fein");</code>
|
||||
<p><code>logger.finer("Feiner");</code>
|
||||
<p><code>logger.finest("Am feinsten");</code>
|
||||
<p>You may toggle the logging level of the console and file handlers by
|
||||
changing the level ALL/OFF/etc. in the constructor.
|
||||
<code>consoleHandler.setLevel(Level.OFF);</code>
|
||||
<code>fileHandler.setLevel(Level.ALL);</code>
|
||||
* Beispiel für Logging-Arten:
|
||||
* <p><code>logger.severe("Schwerwiegender Fehler");</code>
|
||||
* <p><code>logger.warning("Warnung");</code>
|
||||
* <p><code>logger.info("Information");</code>
|
||||
* <p><code>logger.config("Konfigurationshinweis");</code>
|
||||
* <p><code>logger.fine("Fein");</code>
|
||||
* <p><code>logger.finer("Feiner");</code>
|
||||
* <p><code>logger.finest("Am feinsten");</code>
|
||||
* <p>You may toggle the logging level of the console and file handlers by
|
||||
* changing the level ALL/OFF/etc. in the constructor.
|
||||
* <code>consoleHandler.setLevel(Level.OFF);</code>
|
||||
* <code>fileHandler.setLevel(Level.ALL);</code>
|
||||
*/
|
||||
public class RaupenLogger {
|
||||
|
||||
@ -172,9 +172,9 @@ public class RaupenLogger {
|
||||
}
|
||||
String indentString = " ".repeat(indent * 2);
|
||||
logger.info(indentString + abstractSyntaxTree.getClass());
|
||||
//for (ASTNode child : abstractSyntaxTree.getChildren()) {
|
||||
// logAST(child, indent + 1);
|
||||
// }
|
||||
|
||||
// for (ASTNode child : node.) {
|
||||
// printAST(child, indent + 1);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -10,15 +10,17 @@ compile-javac:
|
||||
compile-raupenpiler:
|
||||
cd ../.. ; mvn -DskipTests install
|
||||
cd ../.. ; mvn exec:java -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/raupenpiler
|
||||
|
||||
test: test-javac test-raupenpiler
|
||||
test: compile-javac compile-raupenpiler test-javac test-raupenpiler
|
||||
|
||||
test-javac:
|
||||
#compile-javac
|
||||
#java -cp .\resources\output\javac CompilerInput
|
||||
|
||||
test-raupenpiler:
|
||||
#java -cp .\resources\output\raupenpiler CompilerInput
|
||||
mv ../main/resources/output/CompilerInput.class .java/main/
|
||||
cd .java/main/
|
||||
|
||||
|
||||
|
||||
clean:
|
||||
rm -f ./resources/output/javac/*.class
|
||||
|
@ -1,6 +0,0 @@
|
||||
package main;
|
||||
|
||||
public class EmptyClassExample {
|
||||
private class Inner {
|
||||
}
|
||||
} // -o für outout
|
@ -3,11 +3,11 @@ package main;
|
||||
/**
|
||||
* This class is used to test the output of the compiler.
|
||||
*
|
||||
* <p>Im gleichen Ordner wie diese Datei (main.TestCompilerOutput.java) muss die selbst kompilierte CompilerInput.class Datei sein.
|
||||
* <br><strong>Hinweis:</strong> Diese muss man also vom Ordner <code> main/resources/output </code> in diesen Ordner hier (test/java) rein kopieren. (bis es eine bessere Lösung gibt)</p>
|
||||
* <p>Im gleichen Ordner wie diese Datei (TestCompilerOutput.java) muss die selbst kompilierte CompilerInput.class Datei sein.
|
||||
* <br><strong>Hinweis:</strong> Diese muss man also vom Ordner <code> main/resources/output </code> in diesen Ordner hier (test/java/main) rein kopieren. (bis es eine bessere Lösung gibt)</p>
|
||||
*
|
||||
* <p>Die selbst kompilierte .class Datei wird dann hier drin geladen und eine Instanz von ihr erstellt, es können auch Methoden aufgerufen werden.
|
||||
* <p>Diese main.TestCompilerOutput.java Datei wird dann in <code> \src\test\java> </code> mit <code>javac .\main.TestCompilerOutput.java</code> kompiliert und mit <code>java main.TestCompilerOutput</code> ausgeführt.
|
||||
* <p>Diese TestCompilerOutput.java Datei wird dann in <code> \src\test\java> </code> mit <code>javac .\main.TestCompilerOutput.java</code> kompiliert und mit <code>java main.TestCompilerOutput</code> 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).</p>
|
||||
*
|
||||
|
@ -1,5 +1,18 @@
|
||||
package parser;
|
||||
|
||||
import ast.BlockNode;
|
||||
import ast.ClassNode;
|
||||
import ast.LiteralNode;
|
||||
import ast.ProgramNode;
|
||||
import ast.expression.ExpressionNode;
|
||||
import ast.member.FieldNode;
|
||||
import ast.member.MemberNode;
|
||||
import ast.member.MethodNode;
|
||||
import ast.parameter.ParameterListNode;
|
||||
import ast.parameter.ParameterNode;
|
||||
import ast.statement.ReturnStatementNode;
|
||||
import ast.statement.StatementNode;
|
||||
import ast.type.*;
|
||||
import org.antlr.v4.runtime.*;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -81,6 +94,43 @@ public class ParserTest {
|
||||
public void astBuilderTest() {
|
||||
// TODO: Implement this test method
|
||||
|
||||
// ---------------- Aktuellen CompilerInput nachbauen ----------------
|
||||
ProgramNode startNode = new ProgramNode();
|
||||
// public class CompilerInput {}
|
||||
ClassNode compilerInputClass = new ClassNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), "CompilerInput");
|
||||
// public int a;
|
||||
compilerInputClass.addMember(new FieldNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), new BaseTypeNode(EnumTypeNode.INT), "a"));
|
||||
// public static int testMethod(char x) { return 0; }
|
||||
compilerInputClass.addMember(
|
||||
new MethodNode(
|
||||
new AccessTypeNode(EnumAccessTypeNode.PUBLIC),
|
||||
new BaseTypeNode(EnumTypeNode.INT),
|
||||
"testMethod",
|
||||
new ParameterListNode(List.of(new ParameterNode(new BaseTypeNode(EnumTypeNode.CHAR), "x"))),
|
||||
List.of(new ReturnStatementNode(new LiteralNode(0)))
|
||||
));
|
||||
|
||||
ClassNode testClass = new ClassNode(new AccessTypeNode(EnumAccessTypeNode.PUBLIC), "Test");
|
||||
testClass.addMember(
|
||||
new MethodNode(
|
||||
new AccessTypeNode(EnumAccessTypeNode.PUBLIC),
|
||||
new BaseTypeNode(EnumTypeNode.INT),
|
||||
"testMethod",
|
||||
new ParameterListNode(List.of(new ParameterNode(new BaseTypeNode(EnumTypeNode.CHAR), "x"), new ParameterNode(new BaseTypeNode(EnumTypeNode.INT), "a"))),
|
||||
List.of(new ReturnStatementNode(new LiteralNode(0)))
|
||||
)
|
||||
);
|
||||
|
||||
//compilerInputClass.addClass(testClass);
|
||||
|
||||
startNode.addClass(compilerInputClass);
|
||||
startNode.addClass(testClass);
|
||||
|
||||
// ---------------- Aktuellen CompilerInput nachbauen ----------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user