On 6/24/11 7:49 PM, "Jim Idle" <j...@temporal-wave.com> wrote:
Hi Jim, I do now third attempt switch from ANTLR2 to ANTLR3, And reuse is very important for us, because we do parse SQL strings in the DBMS servers ... I am very happy to read it should work now again in 3.4! But I have got question after this your letter. You say that TreeParser cannot be reused. Then: A) what do method reset() in the generated TreeParser? can/should we use it? If yes when and for what? B) Do you mean that on each loop we must free() Nodes and TreeParser nodes ->free( nodes ); nodes = NULL; treePsr ->free( treePsr ); treePsr = NULL; And then create them again nodes = antlr3CommonTreeNodeStreamNewTree(langAST.tree, ANTLR3_SIZE_HINT); treePsr = SqlTreeParser_v3New( nodes ); Or I can just do on each loop treePsr->reset( treePsr ); Thank you in advance for explain > Because the documentation is not yet up to date, here is an example of > reusing the allocated memory in input streams and token streams: > > > > for (i=0; i<iterations; i++) { > > > > // Run the parser. > > // > > psr->start(psr); > > > > // -------------------------------------- > > // Now reset everything for the next run. > > // Order of calls is important. > > > > // Input stream can now be reused > > // > > input->reuse(input, sourceCode, sourceLen, sourceName); > > > > // Reset the common token stream so that it will reuse its resources > > // > > tstream->reset(tstream); > > > > // Reset the lexer (new function generated by antlr now) > > // > > lxr->reset(lxr); > > > > // Reset the parser (new function generated by antlr now) > > // > > psr->reset(psr); > > } > > > > Note that tree parsers cannot reuse their allocations but this is rarely an > issue. The input->reuse() will reuse any memory it has allocated, but > requires that you handle the reading of the input files (or otherwise supply > a pointer to them). The input files are assumed to be encoded in the way > that the original input was created, for instance: > > > > input = antlr3FileStreamNew(fname, ANTLR3_ENC_8BIT); > > > > Then all reused input must be 8 bit encoded. > > > > Jim > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: > http://www.antlr.org/mailman/options/antlr-interest/your-email-address > -- Best regards, Ruslan Zasukhin VP Engineering and New Technology Paradigma Software, Inc Valentina - Joining Worlds of Information http://www.paradigmasoft.com [I feel the need: the need for speed] List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.