2

我正在尝试以 http://javacc.java.net/doc/errorrecovery.html中给出的 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 无法解析该文件,在“尝试”字和行中显示错误

'void error_skipto(int kind)' .

这样做的正确方法是什么?

提前致谢

This is the error that is coming

在此处输入图像描述

4

1 回答 1

2

显然您使用的不是 JavaCC,而是 JTB 1.3.2。

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

于 2011-11-14T17:38:39.330 回答