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

-- 
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.

Reply via email to