我正在尝试在JavaCC语法中实现错误报告和恢复,如下所示 http://javacc.java.net/doc/errorrecovery.html
提到代码之后;
void Stm() :
{}
{
try {
(
IfStm()
|
WhileStm()
)
catch (ParseException e) {
error_skipto(SEMICOLON);
}
}
void error_skipto(int kind) {
ParseException e = generateParseException(); // generate the exception object.
System.out.println(e.toString()); // print the error message
Token t;
do {
t = getNextToken();
} while (t.kind != kind);
// The above loop consumes tokens all the way up to a token of
// "kind". We use a do-while loop rather than a while because the
// current token is the one immediately before the erroneous token
// (in our case the token immediately before what should have been
// "if"/"while".
}
JavaCC无法解析该文件,在“try”字和
行显示错误'void error_skipto(int kind)' .
这样做的正确方法是什么?
提前致谢
This is the error that is coming
答案 0 :(得分:2)
显然你没有使用JavaCC,而是使用JTB 1.3.2。
JTB可能有.jj语法文件的自己的解析器,并且可能是JTB不支持try-catch的情况,如图所示。在这种情况下,在相同的输入上使用JavaCC会给你一个不同的结果。