Tests, Structure, More #10

Merged
i22005 merged 15 commits from Tests into main 2024-06-21 16:16:54 +00:00
31 changed files with 47 additions and 41 deletions
Showing only changes of commit 2a20a91d35 - Show all commits

View File

@ -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
i22011 marked this conversation as resolved Outdated

Können wir die ganze Ausgabe in ne extra Klasse auzslagern? Des macht die Main Klasse bissle arg unübersichtlich. Außerdem gehört des nacher nicht in den Endgültigen Compiler.

Können wir die ganze Ausgabe in ne extra Klasse auzslagern? Des macht die Main Klasse bissle arg unübersichtlich. Außerdem gehört des nacher nicht in den Endgültigen Compiler.
// 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();
i22011 marked this conversation as resolved Outdated

Same Here

Same Here
// 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 -------------------------*/
i22011 marked this conversation as resolved Outdated

Same Here

Same Here
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");
} }
/** /**
i22011 marked this conversation as resolved Outdated

Same Here

Same Here
* 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

View File

@ -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

View File

@ -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());
} }

View 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