chain one wrote:
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.

Actually it isn't particularly inefficient, it is justa bit of memory and few pointers initialized; though when measured relative to the speed of parsing/lexing it may appear to be so :-). However, there is no need to recreate the lexer and parser, you can reuse them and reset() them, setting their input streams as per the API docs.

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-interest@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
-~----------~----~----~----~------~----~------~--~---



List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to