我正在尝试在JavaCC
语法
我在.jjt
语法文件
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);
}
当我执行命令jjtree CMinus.jjt
时,我收到以下错误:
从文件CMinus_ragu.jjt中读取。 。 。 解析输入时出错:org.javacc.jjtree.ParseException:遇到“”{“”{“”a t第111行,第30栏。 期待以下之一: “抛出”...... “:”...... “#”......
代码中的错误是什么以及我应该如何处理错误恢复?
答案 0 :(得分:1)
应在语法文件中的错误处理程序代码之前添加关键字JAVACODE。因此,该方法应如下所示:
JAVACODE
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);
}
这是因为在使用java样式生成之前应该添加关键字JAVACODE。