如何在JavaCC语法中提到try-catch块

如何在JavaCC语法中提到try-catch块,java,parsing,parser-generator,javacc,Java,Parsing,Parser Generator,Javacc,我正在尝试用JavaCC语法实现错误报告和恢复,如中所示 在提到代码之后 void Stm() : {} { try { ( IfStm() | WhileStm() ) catch (ParseException e) { error_skipto(SEMICOLON); } } void error_skipto(int kind) { ParseException e = generateParseExcepti

我正在尝试用JavaCC语法实现错误报告和恢复,如中所示

在提到代码之后

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

显然,您使用的不是JavaCC,而是JTB1.3.2


JTB可能有自己的.jj语法文件解析器,可能是JTB不支持try-catch,如图所示。在这种情况下,在相同的输入上使用JavaCC应该会得到不同的结果。

在“try”字上显示错误是什么意思。您看到的确切错误消息是什么,它们发生在哪一行?请记住,当我们在这里发布问题时,我们无法从这里看到您的屏幕,我们所拥有的唯一信息是您在问题中提供的信息。如果不知道错误是什么以及你所掌握的关于它的其他信息,“显示错误”是毫无意义的。如果您在发布问题时向我们提供解决问题所需的信息,您将更快地获得帮助。谢谢。:)获取JTB源代码并查看其语法将显示是否支持try-catch。还要寻找比1.3.2更新的版本。