gemeinsame dc 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
3500ffd377
commit
92990e4042
@ -1,25 +1,24 @@
|
|||||||
package ast.literal;
|
package ast.literal;
|
||||||
|
import ast.expressions.IExpressionNode;
|
||||||
import ast.expression.ExpressionNode;
|
import ast.type.type.ITypeNode;
|
||||||
import ast.type.TypeNode;
|
|
||||||
import semantic.SemanticVisitor;
|
import semantic.SemanticVisitor;
|
||||||
import typechecker.TypeCheckResult;
|
import typechecker.TypeCheckResult;
|
||||||
|
|
||||||
public class LiteralNode implements ExpressionNode {
|
public class LiteralNode implements IExpressionNode {
|
||||||
|
|
||||||
public String value;
|
public String value;
|
||||||
private TypeNode type;
|
private ITypeNode type;
|
||||||
|
|
||||||
public LiteralNode(String value, TypeNode type) {
|
public LiteralNode(String value, ITypeNode type) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TypeNode getType() {
|
public ITypeNode getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(TypeNode type) {
|
public void setType(ITypeNode type) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ public class ClassCodeGen implements ClassVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
classWriter.visitEnd();
|
classWriter.visitEnd();
|
||||||
writeToJar(classWriter.toByteArray(), classNode.identifier);
|
|
||||||
printIntoClassFile(classWriter.toByteArray(), classNode.identifier, outputDirectory);
|
printIntoClassFile(classWriter.toByteArray(), classNode.identifier, outputDirectory);
|
||||||
|
writeToJar(classWriter.toByteArray(), classNode.identifier);
|
||||||
|
|
||||||
classWriter.visitEnd();
|
classWriter.visitEnd();
|
||||||
}
|
}
|
||||||
|
@ -91,15 +91,15 @@ public class Main {
|
|||||||
|
|
||||||
/*------------------------- 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
|
||||||
RaupenLogger.logSemanticAnalyzer(typedAst);
|
RaupenLogger.logSemanticAnalyzer(abstractSyntaxTree);
|
||||||
|
|
||||||
/*------------------------- 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);
|
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator(outputDirectoryPath);
|
||||||
assert typedAst != null;
|
assert abstractSyntaxTree != null;
|
||||||
byteCodeGenerator.visit((ProgramNode) typedAst);
|
byteCodeGenerator.visit((ProgramNode) abstractSyntaxTree);
|
||||||
// Log the bytecode generation
|
// Log the bytecode generation
|
||||||
RaupenLogger.logBytecodeGenerator();
|
RaupenLogger.logBytecodeGenerator();
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,15 @@ public class Compiler {
|
|||||||
public int add(int i, int j) {
|
public int add(int i, int j) {
|
||||||
return i+j;
|
return i+j;
|
||||||
}
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int a = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Node {
|
public class Node {
|
||||||
public void main() {
|
public void main() {
|
||||||
Compiler compiler = new Compiler();
|
Compiler compiler = new Compiler();
|
||||||
int i = compiler.add(5, 8);
|
int i = compiler.add(5, 8);
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
src/main/resources/output/output.jar
Normal file
BIN
src/main/resources/output/output.jar
Normal file
Binary file not shown.
@ -10,7 +10,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 -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
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ test-raupenpiler:
|
|||||||
clean:
|
clean:
|
||||||
# clean output folders
|
# clean output folders
|
||||||
rm -f ../main/resources/output/*.class
|
rm -f ../main/resources/output/*.class
|
||||||
|
rm -f ../main/resources/output/*.jar
|
||||||
rm -f ./resources/output/javac/*.class
|
rm -f ./resources/output/javac/*.class
|
||||||
rm -f ./resources/output/raupenpiler/*.class
|
rm -f ./resources/output/raupenpiler/*.class
|
||||||
# clean logs
|
# clean logs
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"classes": [
|
|
||||||
{
|
|
||||||
"identifier": "testClass1",
|
|
||||||
"accessType": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"@type": "Field",
|
|
||||||
"accessTypeNode": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "testVar1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "Method",
|
|
||||||
"visibility": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "testMethod",
|
|
||||||
"parameters": {
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "param1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"statements": [
|
|
||||||
{
|
|
||||||
"@type": "Assignment",
|
|
||||||
"expressionLeft": {
|
|
||||||
"@type": "InstVar",
|
|
||||||
"identifier": "testVar1",
|
|
||||||
"expression": {
|
|
||||||
"@type": "This",
|
|
||||||
"type": {
|
|
||||||
"@type": "Reference",
|
|
||||||
"identifier": "testClass1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": null
|
|
||||||
},
|
|
||||||
"expressionRight": {
|
|
||||||
"@type": "Literal",
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"hasConstructor": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,133 +0,0 @@
|
|||||||
{
|
|
||||||
"classes": [
|
|
||||||
{
|
|
||||||
"identifier": "testClass1",
|
|
||||||
"accessType": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"@type": "Field",
|
|
||||||
"accessTypeNode": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "testVar1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "Method",
|
|
||||||
"visibility": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "testMethod",
|
|
||||||
"parameters": {
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "param1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"statements": [
|
|
||||||
{
|
|
||||||
"@type": "Assignment",
|
|
||||||
"expressionLeft": {
|
|
||||||
"@type": "InstVar",
|
|
||||||
"identifier": "testVar1",
|
|
||||||
"expression": {
|
|
||||||
"@type": "This",
|
|
||||||
"type": {
|
|
||||||
"@type": "Reference",
|
|
||||||
"identifier": "testClass1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": null
|
|
||||||
},
|
|
||||||
"expressionRight": {
|
|
||||||
"@type": "Literal",
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "BOOLEAN"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"hasConstructor": false,
|
|
||||||
"methods": [
|
|
||||||
{
|
|
||||||
"@type": "Method",
|
|
||||||
"visibility": {
|
|
||||||
"enumAccessTypeNode": "PUBLIC"
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "testMethod",
|
|
||||||
"parameters": {
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "INT"
|
|
||||||
},
|
|
||||||
"identifier": "param1"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"statements": [
|
|
||||||
{
|
|
||||||
"@type": "Assignment",
|
|
||||||
"expressionLeft": {
|
|
||||||
"@type": "InstVar",
|
|
||||||
"identifier": "testVar",
|
|
||||||
"expression": {
|
|
||||||
"@type": "InstVar",
|
|
||||||
"identifier": "testVar",
|
|
||||||
"expression": {
|
|
||||||
"@type": "This",
|
|
||||||
"type": {
|
|
||||||
"@type": "Reference",
|
|
||||||
"identifier": "testClass2"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"type": null
|
|
||||||
},
|
|
||||||
"type": null
|
|
||||||
},
|
|
||||||
"expressionRight": {
|
|
||||||
"@type": "Literal",
|
|
||||||
"type": null
|
|
||||||
},
|
|
||||||
"type": null
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"@type": "VariableDeclaration",
|
|
||||||
"type": {
|
|
||||||
"@type": "Base",
|
|
||||||
"enumType": "CHAR"
|
|
||||||
},
|
|
||||||
"identifier": "objectVar",
|
|
||||||
"expression": {
|
|
||||||
"@type": "Literal",
|
|
||||||
"type": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
{"classes":[{"identifier":"testClass","accessType":{"enumAccessTypeNode":"PUBLIC"},"members":[{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar1"},{"@type":"Field","accessTypeNode":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"objectVar"},{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}],"hasConstructor":false,"methods":[{"@type":"Method","visibility":{"enumAccessTypeNode":"PUBLIC"},"type":{"@type":"Base","enumType":"INT"},"identifier":"testVar2","parameters":{"parameters":[{"type":{"@type":"Base","enumType":"INT"},"identifier":"param1"}]},"statements":[{"@type":"Assignment","expressionLeft":{"@type":"InstVar","identifier":"objectVar","expression":{"@type":"This","type":{"@type":"Reference","identifier":"testClass"}},"type":null},"expressionRight":{"@type":"Literal","type":{"@type":"Base","enumType":"INT"}}}]}]}]}
|
|
Loading…
Reference in New Issue
Block a user