catch error to abort further processing
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
// Context Analysis and DAST generation
|
||||||
|
Node root;
|
||||||
|
try {
|
||||||
// Extract information about all functions
|
// Extract information about all functions
|
||||||
var functionDefinitions = new HashMap<String, FunctionInformation>();
|
var functionDefinitions = new HashMap<String, FunctionInformation>();
|
||||||
new GetFunctions(functionDefinitions).visit(tree);
|
new GetFunctions(functionDefinitions).visit(tree);
|
||||||
|
|
||||||
// Context Analysis and DAST generation
|
// Create the DAST
|
||||||
ContextAnalysis ctxAnal = new ContextAnalysis(functionDefinitions);
|
ContextAnalysis ctxAnal = new ContextAnalysis(functionDefinitions);
|
||||||
Node node = ctxAnal.visit(tree); // this gets us the DAST
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user