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);
|
||||
|
||||
// Printing the tokens
|
||||
// tokenStream.fill();
|
||||
// List<Token> tokens = tokenStream.getTokens();
|
||||
// System.out.println("-------------------- Scanner -> tokens
|
||||
// --------------------");
|
||||
// for (Token token : tokens) {
|
||||
// String tokenType =
|
||||
// SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType());
|
||||
// String tokenText = token.getText();
|
||||
// // System.out.println("Token Type: " + tokenType + ", Token Text: " +
|
||||
// // tokenText);
|
||||
// System.out.println(tokenType + " " + tokenText);
|
||||
// }
|
||||
// System.out.println();
|
||||
tokenStream.fill();
|
||||
List<Token> tokens = tokenStream.getTokens();
|
||||
System.out.println("-------------------- Scanner -> tokens --------------------");
|
||||
for (Token token : tokens) {
|
||||
String tokenType =
|
||||
SimpleJavaLexer.VOCABULARY.getSymbolicName(token.getType());
|
||||
String tokenText = token.getText();
|
||||
// System.out.println("Token Type: " + tokenType + ", Token Text: " +
|
||||
// tokenText);
|
||||
System.out.println(tokenType + " " + tokenText);
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
/*------------------------- Parser -> Parsetree -------------------------*/
|
||||
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
|
||||
ParseTree parseTree = parser.program(); // parse the input
|
||||
|
||||
// Printing the parse tree
|
||||
// System.out.println("-------------------- Parser -> Parsetree
|
||||
// --------------------");
|
||||
// System.out.println(parseTree.toStringTree(parser));
|
||||
// printTree(parseTree, parser, 0);
|
||||
// System.out.println();
|
||||
System.out.println("-------------------- Parser -> Parsetree --------------------");
|
||||
System.out.println(parseTree.toStringTree(parser));
|
||||
printTree(parseTree, parser, 0);
|
||||
System.out.println();
|
||||
|
||||
/*------------------------- AST builder -> AST -------------------------*/
|
||||
ASTBuilder astBuilder = new ASTBuilder();
|
||||
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
|
||||
|
||||
// Printing the AST
|
||||
// System.out.println("-------------------- AST builder -> AST
|
||||
// --------------------");
|
||||
// // System.out.println("AST: " + ast.toString());
|
||||
// printAST(abstractSyntaxTree, 0);
|
||||
// System.out.println();
|
||||
System.out.println("-------------------- AST builder -> AST --------------------");
|
||||
// System.out.println("AST: " + ast.toString());
|
||||
printAST(abstractSyntaxTree, 0);
|
||||
System.out.println();
|
||||
|
||||
/*------------------------- Semantic Analyzer -> Tast -------------------------*/
|
||||
SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
||||
/*------------------------- Semantic Analyzer -> typed AST -------------------------*/
|
||||
ProgramNode typedAst = (ProgramNode) SemanticAnalyzer.generateTast(abstractSyntaxTree);
|
||||
|
||||
// Printing the Tast
|
||||
System.out.println("Tast generated");
|
||||
// Printing the typed AST
|
||||
System.out.println("-------------------- Semantic Analyzer -> typed AST --------------------");
|
||||
printAST(typedAst, 0);
|
||||
System.out.println();
|
||||
|
||||
/*------------------------- Bytecode Generator -> Bytecode -------------------------*/
|
||||
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
|
||||
// byteCodeGenerator.generateByteCode(abstractSyntaxTree);
|
||||
byteCodeGenerator.visit(typedAst);
|
||||
System.out.println("Bytecode generated");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
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() {
|
||||
CharStream codeCharStream = null;
|
||||
try {
|
||||
codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.txt"));
|
||||
Main.parsefile(codeCharStream);
|
||||
codeCharStream = CharStreams.fromPath(Paths.get("src/main/test/resources/CompilerInput.java"));
|
||||
Main.parseFile(codeCharStream);
|
||||
} catch (IOException e) {
|
||||
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