Endabgabe #20
@ -13,6 +13,7 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -20,9 +21,9 @@ import java.nio.file.Paths;
|
|||||||
* <p> <code> cd .\src\test\ </code>
|
* <p> <code> cd .\src\test\ </code>
|
||||||
* <p> <code> make clean compile-raupenpiler </code>
|
* <p> <code> make clean compile-raupenpiler </code>
|
||||||
* <p> Start Raupenpiler using jar:
|
* <p> Start Raupenpiler using jar:
|
||||||
* <p> <code> java.exe -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 -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>
|
||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
@ -97,7 +98,11 @@ public class Main {
|
|||||||
|
|
||||||
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
||||||
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
|
// Use the ByteCodeGenerator to generate bytecode from the typed AST and output it to the specified directory
|
||||||
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, true, true);
|
|
||||||
|
final boolean genJar = Optional.ofNullable(System.getProperty("genJar")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
|
||||||
|
final boolean genClass = Optional.ofNullable(System.getProperty("genClass")).map(String::toLowerCase).map(Boolean::parseBoolean).orElse(true);
|
||||||
|
|
||||||
|
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath, genJar, genClass);
|
||||||
assert typedAst != null;
|
assert typedAst != null;
|
||||||
byteCodeGenerator.visit((ProgramNode) typedAst);
|
byteCodeGenerator.visit((ProgramNode) typedAst);
|
||||||
// Log the bytecode generation
|
// Log the bytecode generation
|
||||||
|
@ -9,7 +9,7 @@ compile-javac:
|
|||||||
|
|
||||||
compile-raupenpiler:
|
compile-raupenpiler:
|
||||||
cd ../.. ; mvn -DskipTests install
|
cd ../.. ; mvn -DskipTests install
|
||||||
cd ../.. ; mvn exec:java -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/raupenpiler
|
cp ../main/resources/output/CompilerInput.class .java/resources/output/raupenpiler
|
||||||
|
|
||||||
test: compile-javac compile-raupenpiler test-javac test-raupenpiler
|
test: compile-javac compile-raupenpiler test-javac test-raupenpiler
|
||||||
|
@ -2,112 +2,4 @@ package semantic;
|
|||||||
|
|
||||||
public class SemanticTest {
|
public class SemanticTest {
|
||||||
|
|
||||||
|
|
||||||
public void test(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test(int a, boolean b){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test(boolean b, int a){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Test
|
|
||||||
// public void alreadyDeclaredLocalFieldVar() {
|
|
||||||
// ProgramNode programNode = new ProgramNode();
|
|
||||||
// List<ClassNode> classList = new ArrayList<>();
|
|
||||||
// AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC);
|
|
||||||
// ClassNode classNode = new ClassNode(accessTypeNode, "testClass");
|
|
||||||
//
|
|
||||||
// SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
|
|
||||||
// ASTNode tast = semanticAnalyzer.generateTast(ast);
|
|
||||||
//
|
|
||||||
// MemberNode memberNode2 = new FieldNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar");
|
|
||||||
// classNode.members.add(memberNode2);
|
|
||||||
//
|
|
||||||
// classList.add(classNode);
|
|
||||||
// programNode.classes = classList;
|
|
||||||
//
|
|
||||||
// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
|
|
||||||
//
|
|
||||||
// assertEquals(1, SemanticAnalyzer.errors.size());
|
|
||||||
// assertInstanceOf(AlreadyDeclaredException.class, SemanticAnalyzer.errors.getFirst());
|
|
||||||
// assertNull(typedAst);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// public void shouldWorkWithNoError() {
|
|
||||||
// ProgramNode programNode = new ProgramNode();
|
|
||||||
// List<ClassNode> classList = new ArrayList<>();
|
|
||||||
// AccessTypeNode accessTypeNode = new AccessTypeNode(EnumAccessTypeNode.PUBLIC);
|
|
||||||
// ClassNode classNode = new ClassNode(accessTypeNode, "testClass");
|
|
||||||
//
|
|
||||||
// SemanticAnalyzer semanticAnalyzer = new SemanticAnalyzer();
|
|
||||||
// ASTNode tast = semanticAnalyzer.generateTast(ast);
|
|
||||||
//
|
|
||||||
// assertEquals(semanticAnalyzer.errors.size(), 0);
|
|
||||||
// assertNotNull(tast);
|
|
||||||
//
|
|
||||||
// MemberNode memberNode3 = getMemberNode(accessTypeNode);
|
|
||||||
// classNode.members.add(memberNode3);
|
|
||||||
//
|
|
||||||
// classList.add(classNode);
|
|
||||||
// programNode.classes = classList;
|
|
||||||
//
|
|
||||||
// ASTNode typedAst = SemanticAnalyzer.generateTast(programNode);
|
|
||||||
//
|
|
||||||
// assertEquals(0, SemanticAnalyzer.errors.size());
|
|
||||||
// assertEquals(programNode, typedAst);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * This method is used to create a MemberNode representing a method.
|
|
||||||
// * It first creates a list of ParameterNodes and adds a ParameterNode to it.
|
|
||||||
// * Then, it creates a ParameterListNode using the list of ParameterNodes.
|
|
||||||
// * After that, it creates a list of StatementNodes and adds a StatementNode to it by calling the getStatementNode method.
|
|
||||||
// * Finally, it creates a MethodNode using the provided AccessTypeNode, a BaseTypeNode representing the return type of the method,
|
|
||||||
// * the method name, the ParameterListNode, and the list of StatementNodes, and returns this MethodNode.
|
|
||||||
// *
|
|
||||||
// * @param accessTypeNode The AccessTypeNode representing the access type of the method.
|
|
||||||
// * @return The created MemberNode representing the method.
|
|
||||||
// */
|
|
||||||
//private static MemberNode getMemberNode(AccessTypeNode accessTypeNode) {
|
|
||||||
// List<ParameterNode> parameterNodeList = new ArrayList<>();
|
|
||||||
// ParameterNode parameterNode1 = new ParameterNode(new BaseTypeNode(EnumTypeNode.INT), "param1");
|
|
||||||
// parameterNodeList.add(parameterNode1);
|
|
||||||
// ParameterListNode parameterListNode = new ParameterListNode(parameterNodeList);
|
|
||||||
//
|
|
||||||
// List<StatementNode> statementNodeList = new ArrayList<>();
|
|
||||||
//
|
|
||||||
// StatementNode statementNode1 = getStatementNode();
|
|
||||||
// statementNodeList.add(statementNode1);
|
|
||||||
//
|
|
||||||
// return new MethodNode(accessTypeNode, new BaseTypeNode(EnumTypeNode.INT), "testVar2", parameterListNode, statementNodeList);
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * This method is used to create a StatementNode for an assignment operation.
|
|
||||||
// * It first creates two IdentifierExpressionNodes for 'this' and 'objectVar'.
|
|
||||||
// * Then, it creates a BinaryExpressionNode to represent the operation 'this.objectVar'.
|
|
||||||
// * After that, it creates a LiteralNode to represent the integer value 1.
|
|
||||||
// * Finally, it creates another BinaryExpressionNode to represent the assignment operation 'this.objectVar = 1',
|
|
||||||
// * and wraps this expression in an AssignmentStatementNode.
|
|
||||||
// *
|
|
||||||
// * @return The created AssignmentStatementNode representing the assignment operation 'this.objectVar = 1'.
|
|
||||||
// */
|
|
||||||
//private static StatementNode getStatementNode() {
|
|
||||||
// ExpressionNode expressionNodeObjectVariableLeft = new IdentifierExpressionNode("this");
|
|
||||||
// ExpressionNode expressionNodeObjectVariableRight = new IdentifierExpressionNode("objectVar");
|
|
||||||
//
|
|
||||||
// ExpressionNode expressionNodeLeft = new BinaryExpressionNode(expressionNodeObjectVariableLeft, expressionNodeObjectVariableRight, ExpresssionOperator.DOT);
|
|
||||||
//
|
|
||||||
// ExpressionNode expressionNodeRight = new LiteralNode(1);
|
|
||||||
//
|
|
||||||
// BinaryExpressionNode expressionNode = new BinaryExpressionNode(expressionNodeLeft, expressionNodeRight, ExpresssionOperator.ASSIGNMENT);
|
|
||||||
//
|
|
||||||
// return new AssignmentStatementNode(expressionNode);
|
|
||||||
//}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user