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

て烟熏妆下的殇ゞ 提交于 2019-12-24 07:07:16

问题


i am using eclipse and JavaCC plugin 1.5.27
i want to use the parser to be executed more than only once. it goes perfect, if using only once. running the parser within the program a second time i get an error:

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

so i add the ReInit() after parsing, but this does not help. this is the code snipped.

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

looking for all answers from google, but without results. so i am really wondering if i am the only one with this issue.

any help would be great.

kind regards
hans

--


回答1:


As I said in my comment, I generally use nonstatic parser. The following "Answer" is more a guess than an authoritative answer. If you try it, please comment, so others (and I) can know whether it's right.

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();
    .....

}



来源:https://stackoverflow.com/questions/22737697/javacc-you-must-either-use-reinit-or-set-the-javacc-option-static-to-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!