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);
// 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
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
// 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();
i22011 marked this conversation as resolved Outdated

Same Here

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

Same Here

Same Here
ByteCodeGenerator byteCodeGenerator = new ByteCodeGenerator();
// byteCodeGenerator.generateByteCode(abstractSyntaxTree);
byteCodeGenerator.visit(typedAst);
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.
* 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() {
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());
}

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