Refactor structure and more
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
b2e1745d51
commit
2a20a91d35
@ -37,57 +37,55 @@ public class Main {
|
|||||||
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
|
||||||
|
|
||||||
// Printing the tokens
|
// Printing the tokens
|
||||||
// tokenStream.fill();
|
tokenStream.fill();
|
||||||
// List<Token> tokens = tokenStream.getTokens();
|
List<Token> tokens = tokenStream.getTokens();
|
||||||
// System.out.println("-------------------- Scanner -> tokens
|
System.out.println("-------------------- Scanner -> tokens --------------------");
|
||||||
// --------------------");
|
for (Token token : tokens) {
|
||||||
// for (Token token : tokens) {
|
String tokenType =
|
||||||
// String tokenType =
|
SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType());
|
||||||
// SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType());
|
String tokenText = token.getText();
|
||||||
// String tokenText = token.getText();
|
// System.out.println("Token Type: " + tokenType + ", Token Text: " +
|
||||||
// // System.out.println("Token Type: " + tokenType + ", Token Text: " +
|
// tokenText);
|
||||||
// // tokenText);
|
System.out.println(tokenType + " " + tokenText);
|
||||||
// System.out.println(tokenType + " " + tokenText);
|
}
|
||||||
// }
|
System.out.println();
|
||||||
// System.out.println();
|
|
||||||
|
|
||||||
/*------------------------- Parser -> Parsetree -------------------------*/
|
/*------------------------- Parser -> 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
|
||||||
|
|
||||||
// Printing the parse tree
|
// Printing the parse tree
|
||||||
// System.out.println("-------------------- Parser -> Parsetree
|
System.out.println("-------------------- Parser -> Parsetree --------------------");
|
||||||
// --------------------");
|
System.out.println(parseTree.toStringTree(parser));
|
||||||
// System.out.println(parseTree.toStringTree(parser));
|
printTree(parseTree, parser, 0);
|
||||||
// printTree(parseTree, parser, 0);
|
System.out.println();
|
||||||
// System.out.println();
|
|
||||||
|
|
||||||
/*------------------------- AST builder -> AST -------------------------*/
|
/*------------------------- AST builder -> AST -------------------------*/
|
||||||
ASTBuilder astBuilder = new ASTBuilder();
|
ASTBuilder astBuilder = new ASTBuilder();
|
||||||
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
||||||
|
|
||||||
// Printing the AST
|
// Printing the AST
|
||||||
// System.out.println("-------------------- AST builder -> AST
|
System.out.println("-------------------- AST builder -> AST --------------------");
|
||||||
// --------------------");
|
// System.out.println("AST: " + ast.toString());
|
||||||
// // System.out.println("AST: " + ast.toString());
|
printAST(abstractSyntaxTree, 0);
|
||||||
// printAST(abstractSyntaxTree, 0);
|
System.out.println();
|
||||||
// System.out.println();
|
|
||||||
|
|
||||||
/*------------------------- Semantic Analyzer -> Tast -------------------------*/
|
/*------------------------- Semantic Analyzer -> typed AST -------------------------*/
|
||||||
SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
|
||||||
ProgramNode typedAst = (ProgramNode) SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
ProgramNode typedAst = (ProgramNode) SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
||||||
|
|
||||||
// Printing the Tast
|
// Printing the typed AST
|
||||||
System.out.println("Tast generated");
|
System.out.println("-------------------- Semantic Analyzer -> typed AST --------------------");
|
||||||
|
printAST(typedAst, 0);
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
||||||
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
|
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
|
||||||
// byteCodeGenerator.generateByteCode(abstractSyntaxTree);
|
|
||||||
byteCodeGenerator.visit(typedAst);
|
byteCodeGenerator.visit(typedAst);
|
||||||
System.out.println("Bytecode generated");
|
System.out.println("Bytecode generated");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is used to print the parse tree in a structured format.
|
* This method is used to print the parse tree in a structured format.
|
||||||
* It recursively traverses the tree and prints the rule names and text of the
|
* It recursively traverses the tree and prints the rule names and text of the
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,11 +0,0 @@
|
|||||||
public class Tester {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
new EmptyClassExample();
|
|
||||||
// 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
|
|
@ -21,8 +21,8 @@ public class MainTest {
|
|||||||
void testEmptyClass() {
|
void testEmptyClass() {
|
||||||
CharStream codeCharStream = null;
|
CharStream codeCharStream = null;
|
||||||
try {
|
try {
|
||||||
codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.txt"));
|
codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.java"));
|
||||||
Main.parsefile(codeCharStream);
|
Main.parseFile(codeCharStream);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Error reading the file: " + e.getMessage());
|
System.err.println("Error reading the file: " + e.getMessage());
|
||||||
}
|
}
|
19
src/test/java/test/java/Tester.java
Normal file
19
src/test/java/test/java/Tester.java
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
public class Tester {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// für E2E Tests:
|
||||||
|
// Testdatei mit Main ausführen/kompilieren
|
||||||
|
// Testdatei mit "javac CompilerInput.java" kompilieren
|
||||||
|
|
||||||
|
// wenn beides erfolgreich
|
||||||
|
// Ergebnis vom eigenen Compiler mit "java myOutput" ausführen
|
||||||
|
// Ergebnis von javac mit "java CompilerInput" ausführen
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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
|
Loading…
Reference in New Issue
Block a user