better exception for parsing
This commit is contained in:
@ -71,11 +71,11 @@ public class LL1Parser {
|
|||||||
} else if (this.parsetable.getTerminals().contains(top)) {
|
} else if (this.parsetable.getTerminals().contains(top)) {
|
||||||
// Wenn das Terminal auf dem Stack nicht mit der aktuellen Eingabe übereinstimmt
|
// 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) {
|
} else if (prod == null) {
|
||||||
// Wenn es für das aktuelle Terminal und das Nichtterminal auf dem Stack keine Regel gibt
|
// 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 {
|
} else {
|
||||||
// Wenn das Nichtterminal auf dem Stack durch (s)eine Produktion ersetzt werden kann
|
// Wenn das Nichtterminal auf dem Stack durch (s)eine Produktion ersetzt werden kann
|
||||||
// Hier wird auch der AST aufgebaut
|
// Hier wird auch der AST aufgebaut
|
||||||
|
|||||||
@ -1,8 +1,18 @@
|
|||||||
package parser;
|
package parser;
|
||||||
|
|
||||||
|
import util.ast.AST;
|
||||||
|
|
||||||
|
import static util.tools.Logger.log;
|
||||||
|
|
||||||
public class MyParseException extends RuntimeException {
|
public class MyParseException extends RuntimeException {
|
||||||
|
|
||||||
public MyParseException(String message) {
|
public MyParseException(String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MyParseException(String message, AST ast) {
|
||||||
|
super(message);
|
||||||
|
|
||||||
|
log("\nAST at last state:\n" + ast);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user