slight formatting changes
This commit is contained in:
2
.idea/CompilerProjekt.iml
generated
2
.idea/CompilerProjekt.iml
generated
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="CompilerProjekt:main" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="de.churl" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
|
||||
<module external.linked.project.id="CompilerProjekt" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="de.churl" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
|
||||
<component name="CheckStyle-IDEA-Module">
|
||||
<option name="configuration">
|
||||
<map />
|
||||
|
10
build.gradle
10
build.gradle
@ -9,6 +9,16 @@ version '1.0-SNAPSHOT'
|
||||
sourceCompatibility = '14'
|
||||
mainClassName = 'StupsCompiler'
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes "Main-Class": "$mainClassName"
|
||||
}
|
||||
|
||||
from {
|
||||
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
}
|
||||
|
||||
generateGrammarSource {
|
||||
outputDirectory = file("src/main/java/lexer")
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public final class StupsCompiler {
|
||||
tree.postprocess(grammar);
|
||||
TypeChecker.validate(tree);
|
||||
|
||||
System.out.println("Compilation completed.");
|
||||
System.out.println("\nCompilation completed.");
|
||||
}
|
||||
|
||||
private static void liveness(String filename) {
|
||||
|
@ -7,8 +7,6 @@ import parser.ast.ASTNode;
|
||||
import parser.grammar.Grammar;
|
||||
import parser.grammar.GrammarAnalyzer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
@ -24,16 +22,13 @@ public class StupsParser {
|
||||
this.parsetable = parsetable;
|
||||
}
|
||||
|
||||
public static StupsParser fromGrammar(Path path) throws IOException {
|
||||
return StupsParser.fromGrammar(Grammar.fromFile(path));
|
||||
}
|
||||
|
||||
public static StupsParser fromGrammar(Grammar grammar) {
|
||||
final GrammarAnalyzer analyzer = new GrammarAnalyzer(grammar);
|
||||
return new StupsParser(analyzer.getTable());
|
||||
}
|
||||
|
||||
public AST parse(List<? extends Token> token, Vocabulary voc) {
|
||||
System.out.println(" - Parsing program...");
|
||||
final ASTNode root = new ASTNode(this.parsetable.getStartSymbol(), 0);
|
||||
final AST tree = new AST(root);
|
||||
final Deque<ASTNode> stack = new ArrayDeque<>();
|
||||
@ -118,7 +113,7 @@ public class StupsParser {
|
||||
log("\nParsed AST:\n" + tree);
|
||||
log("-".repeat(100) + "\n");
|
||||
|
||||
System.out.println("- Parsing successful.");
|
||||
System.out.println("Parsing successful.");
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ public class AST {
|
||||
public void postprocess(Grammar grammar) {
|
||||
ASTCompacter.clean(this, grammar);
|
||||
ASTBalancer.balance(this);
|
||||
System.out.println("Tree processing successful.");
|
||||
}
|
||||
|
||||
public AST deepCopy() {
|
||||
|
@ -52,7 +52,7 @@ public final class ASTBalancer {
|
||||
log(tree.toString());
|
||||
log("-".repeat(100));
|
||||
|
||||
System.out.println("- Tree balancing successful.");
|
||||
System.out.println(" - Balancing syntax-tree...");
|
||||
}
|
||||
|
||||
// Baum spiegeln, damit höhere Ebenen links sind und EXPR vorwärts laufen
|
||||
|
@ -23,7 +23,7 @@ public final class ASTCompacter {
|
||||
|
||||
log("\nCleaned Tree:\n" + tree);
|
||||
log("-".repeat(100));
|
||||
System.out.println("- Tree compression successful.");
|
||||
System.out.println(" - Compressing syntax-tree...");
|
||||
}
|
||||
|
||||
// Entfernt [promote]-able Nodes (Reicht Werte nach oben)
|
||||
|
@ -63,6 +63,7 @@ public class Grammar {
|
||||
}
|
||||
|
||||
public static Grammar fromFile(Path path) throws IOException {
|
||||
System.out.println(" - Reading parser-grammar...");
|
||||
List<String> lines = Files.readAllLines(path);
|
||||
|
||||
lines = lines.stream()
|
||||
@ -182,6 +183,7 @@ public class Grammar {
|
||||
|
||||
log("\n" + actions);
|
||||
log("-".repeat(100));
|
||||
System.out.println("Grammar parsed successfully.");
|
||||
|
||||
return new Grammar(terminals, nonterminals,
|
||||
startSymbol, epsilonSymbol,
|
||||
|
@ -31,12 +31,14 @@ public class GrammarAnalyzer {
|
||||
log("Analyzing Grammar:\n");
|
||||
|
||||
// Es muss zwingend in der Reihenfolge [Nullable < First < Follow < Table] initialisiert werden
|
||||
System.out.println(" - Initializing first-set...");
|
||||
this.first = this.initFirst();
|
||||
System.out.println(" - Initializing follow-set...");
|
||||
this.follow = this.initFollow();
|
||||
|
||||
System.out.println(" - Initializing parse-table...");
|
||||
this.table = this.initParseTable();
|
||||
|
||||
System.out.println("\n- Grammar analysis successful.");
|
||||
System.out.println("Grammar analysis successful.");
|
||||
}
|
||||
|
||||
private Map<String, Set<String>> initFirst() {
|
||||
|
@ -23,11 +23,13 @@ public final class TypeChecker {
|
||||
final TypeTable table = TypeTable.fromAST(tree);
|
||||
final Map<ASTNode, String> nodeTable = new HashMap<>();
|
||||
|
||||
System.out.println(" - Validating syntax-tree...");
|
||||
|
||||
log("Typevalidation:");
|
||||
validate(tree.getRoot(), table, nodeTable);
|
||||
log("-".repeat(100));
|
||||
|
||||
System.out.println("- Typechecking successful.\n");
|
||||
System.out.println("Typechecking successful.");
|
||||
}
|
||||
|
||||
private static void validate(ASTNode root, TypeTable table, Map<ASTNode, String> nodeTable) {
|
||||
|
@ -54,6 +54,7 @@ public class TypeTable {
|
||||
}
|
||||
|
||||
public static TypeTable fromAST(AST tree) {
|
||||
System.out.println(" - Building TypeTable...");
|
||||
final Map<String, String> tableOut = new HashMap<>();
|
||||
|
||||
log("Creating TypeTable");
|
||||
|
Reference in New Issue
Block a user