[antlr-interest] Could the parser and lexer be reused?

chain one chainone at gmail.com
Sun Jan 4 19:57:41 PST 2009


There are many pieces of  inputs , all of which should be parsed by one
parser.Such as :
Input 1:
     Jack 100$
Input 2:
    Tom   200$
Input ......

However, this kind of inputs doesn't come all in one time. They arrive at
different time. Once one input arrives, it needs to be parsed immediately.
So the next piece of pseudo code shows how it is processed by my way:

void ParseOneInput(const char* data)
{
   input  =
antlr3NewAsciiStringInPlaceStream((pANTLR3_UINT8) data,strlen(data),NULL);
   lex    = StepDataEntryLexerNew(m_input);
   tokens = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT,
TOKENSOURCE(lex));
   parser = DataEntryParserNew               (tokens);
    parser  ->entry(parser,1);
    parser ->free(parser);
    tokens ->free(tokens);
    lex    ->free(lex);
    input  ->close(input);
}

Once one input arrives, Function ParseOneInput is called.

It works fine.

The question is , could the parser and lexer in ParseOneInput be reused?
If they could be reused, then it is unnecessary to create/destroy a lexer
and a parser every time an input arrives. If not, I believe it
is inefficient.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090105/b47deb03/attachment.html 


More information about the antlr-interest mailing list