java如何在JavaCC语法中提到trycatch块
我正在尝试用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
# 1 楼答案
显然,您使用的不是JavaCC,而是JTB1.3.2
JTB大概有自己的语法分析器。jj语法文件,可能是JTB不支持try-catch,如图所示。在这种情况下,在相同的输入上使用JavaCC应该会得到不同的结果