0

I create an input stream from a string with

pANTLR3_UINT8 input_string = (pANTLR3_UINT8) "test"; pANTLR3_INPUT_STREAM stream = antlr3StringStreamNew(input_string, ANTLR3_ENC_8BIT, sizeof(input_string), (pANTLR3_UINT8)"testname"); 

and then use my lexer and parser to process the string. When I'm done with this string I want to process a new one, but re-creating the lexer and parser objects seems inefficient.

I've found the reset method of the lexer and parser classes and the reuse method of the stream, but how do I use those to parse a new string?

1 Answer 1

1

I believe what you're looking for is the setCharStream() function.

Sign up to request clarification or add additional context in comments.

2 Comments

Do I also need to call reset on the lexer/parser/stream? Would you mind providing a short example?
You shouldn't need to call reset() manually; the C version resets most of the internal variables (and comments near calls to setCharStream() mention resetting the state). (The Java version calls reset() explicitly, too.) You should just be able to create a new pANTLR3_INPUT_STREAM for your new stream and reset with setCharStream(lexer, new_stream), constructing the stream as you've already done.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.