better exception for parsing

This commit is contained in:
ChUrl
2020-12-08 00:56:48 +01:00
parent e25b43893b
commit 96f2013701
2 changed files with 12 additions and 2 deletions

View File

@ -71,11 +71,11 @@ public class LL1Parser {
} else if (this.parsetable.getTerminals().contains(top)) {
// Wenn das Terminal auf dem Stack nicht mit der aktuellen Eingabe übereinstimmt
throw new MyParseException("Invalid terminal on stack: " + top);
throw new MyParseException("Invalid terminal on stack: " + top, tree);
} else if (prod == null) {
// Wenn es für das aktuelle Terminal und das Nichtterminal auf dem Stack keine Regel gibt
throw new MyParseException("No prod. for nonterminal " + top + ", terminal " + currentToken);
throw new MyParseException("No prod. for nonterminal " + top + ", terminal " + currentToken, tree);
} else {
// Wenn das Nichtterminal auf dem Stack durch (s)eine Produktion ersetzt werden kann
// Hier wird auch der AST aufgebaut

View File

@ -1,8 +1,18 @@
package parser;
import util.ast.AST;
import static util.tools.Logger.log;
public class MyParseException extends RuntimeException {
public MyParseException(String message) {
super(message);
}
public MyParseException(String message, AST ast) {
super(message);
log("\nAST at last state:\n" + ast);
}
}