[antlr-interest] C target; need to close stream?

Gavin Lambert antlr at mirality.co.nz
Wed Sep 5 04:23:16 PDT 2007


At 22:26 5/09/2007, Rupert Mazzucco wrote:
 >when I do the wiki sequence
 >
 >  pANTLR3_INPUT_STREAM
 >      pIStream =
 >antlr3AsciiFileStreamNew((pANTLR3_UINT8)filename);
 >  ...
 >  pParser->file(pParser);
 >
 >do I need to close the file stream somehow and make a new input
 >stream object before I can lex and parse the same file again
 >(with a different grammar), or can I reuse the pIStream handler
 >as is?

Have a look in antlr3input.h -- there's a "reset" method on that 
object that should reset it back to the beginning so you can pass 
it to another lexer.

 >Do the old lexer and parser have methods to "delete" them, and 
is
 >this necessary?

Yes, they do (have a look in the header files, and the 
examples).  It's not strictly necessary, since any memory/handles 
etc allocated by your program will get cleaned up by the OS when 
the program exits, but it's polite to close things when you're 
done with them.  Especially if the program is going to continue 
running for a while after finishing the parse, or if you're 
parsing in a loop.



More information about the antlr-interest mailing list