catch error to abort further processing

This commit is contained in:
2020-02-03 22:21:30 +01:00
parent cb0d63a71c
commit 3e8a904cb8

View File

@@ -83,29 +83,35 @@ public class Klang {
// Parse tokens to AST // Parse tokens to AST
ParseTree tree = parser.parse(); // begin parsing at init rule ParseTree tree = parser.parse(); // begin parsing at init rule
// Extract information about all functions
var functionDefinitions = new HashMap<String, FunctionInformation>();
new GetFunctions(functionDefinitions).visit(tree);
// Context Analysis and DAST generation // Context Analysis and DAST generation
ContextAnalysis ctxAnal = new ContextAnalysis(functionDefinitions); Node root;
Node node = ctxAnal.visit(tree); // this gets us the DAST try {
// Extract information about all functions
var functionDefinitions = new HashMap<String, FunctionInformation>();
new GetFunctions(functionDefinitions).visit(tree);
// Create the DAST
ContextAnalysis ctxAnal = new ContextAnalysis(functionDefinitions);
root = ctxAnal.visit(tree);
} catch (Exception e) {
System.err.println(e.getMessage());
return;
}
if (prettyPrint) { if (prettyPrint) {
// Pretty Print the sourcecode // Pretty Print the sourcecode
StringWriter w = new StringWriter(); StringWriter w = new StringWriter();
PrettyPrintVisitor.ExWriter ex = new PrettyPrintVisitor.ExWriter(w); PrettyPrintVisitor.ExWriter ex = new PrettyPrintVisitor.ExWriter(w);
PrettyPrintVisitor printVisitor = new PrettyPrintVisitor(ex); PrettyPrintVisitor printVisitor = new PrettyPrintVisitor(ex);
node.welcome(printVisitor); root.welcome(printVisitor);
generateOutput(out, w.toString()); System.out.println(w.toString());
return;
} }
if (evaluate) { if (evaluate) {
// Evaluate the sourcecode and print the result // Evaluate the sourcecode and print the result
System.out.println("\nEvaluating the source code:"); System.out.println("\nEvaluating the source code:");
EvalVisitor evalVisitor = new EvalVisitor(); EvalVisitor evalVisitor = new EvalVisitor();
Value result = node.welcome(evalVisitor); Value result = root.welcome(evalVisitor);
if (result != null) { if (result != null) {
generateOutput(out, "Result was: TODO"); generateOutput(out, "Result was: TODO");
} else { } else {
@@ -119,7 +125,7 @@ public class Klang {
StringWriter wAsm = new StringWriter(); StringWriter wAsm = new StringWriter();
GenASM.ExWriter exAsm = new GenASM.ExWriter(wAsm); GenASM.ExWriter exAsm = new GenASM.ExWriter(wAsm);
GenASM genasm = new GenASM(exAsm, mainName); GenASM genasm = new GenASM(exAsm, mainName);
node.welcome(genasm); root.welcome(genasm);
generateOutput(out, wAsm.toString()); generateOutput(out, wAsm.toString());
} }
} }