-->

JavaCC的:你必须使用重新初始化()或设置静态到假的JavaCC选项(JavaCC: You m

2019-10-19 17:31发布

我使用Eclipse和的JavaCC插件1.5.27
我想用它来执行速度比一次更分析器。 它会完美的,如果只使用一次。 运行程序中解释第二次我得到一个错误:

ERROR: Second call to constructor of static parser.  
       You must either use ReInit() or set the JavaCC option STATIC to false
       during parser generation.

所以我添加了重新初始化()解析后,但是这并没有帮助。 这是剪断的代码。

  public static void myParser(String toanalyze) throws ParseException
  {
    InputStream is = new ByteArrayInputStream( toanalyze.getBytes() );
    SQLwhereS parser = new SQLwhereS(is);
    .....
    SQLwhereS.one_line();
    .....
    ReInit(is);
  }

寻找来自谷歌所有的答案,但没有结果。 所以我真的不知道,如果我是唯一一个与此问题。

任何帮助将是巨大的。

亲切的问候
汉斯

-

Answer 1:

正如我在我的评论说,我一般使用非静态解析器。 下面的“答案”是一个多权威的答案猜测。 如果你尝试它,请发表评论,这样其他人(我)可以知道它是否是正确的。

static SQLwhereS parser = null ;

public static void myParser(String toanalyze) throws ParseException
{
    InputStream is = new ByteArrayInputStream( toanalyze.getBytes() );
    if( parser==null) parser = new SQLwhereS(is); else ReInit(is) ;
    .....
    SQLwhereS.one_line();
    .....

}



文章来源: JavaCC: You must either use ReInit() or set the JavaCC option STATIC to false