Question

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.

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);
}
Was it helpful?

Solution

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

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top