Streaming Parser
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Tony_Seebregts
Posted On:   Wednesday, November 27, 2002 02:34 AM

How do I implement a 'streaming' parser ? i.e. one where I instantiate the parser only once and then reuse it to evaluate different expressions. At the moment the code looks like: void X::evalute(std::string query) { std::stringstring in; in < < query; MyLexer lexer(in) MyParser parser(lexer); lexer.setFilename (" "); parser.setFilename(" "); parser.expression (); } and I would like it to look like void X::evalute(std::string query) { in < < query; parser.expression (); } where in , lexer and parser a   More>>

How do I implement a 'streaming' parser ? i.e. one where I instantiate the parser only once and then reuse it to evaluate different expressions.

At the moment the code looks like:

			
void X::evalute(std::string query)
{ std::stringstring in;

in < < query;

MyLexer lexer(in)
MyParser parser(lexer);

lexer.setFilename (" ");
parser.setFilename(" ");
parser.expression ();
}


and I would like it to look like

			
void X::evalute(std::string query)
{ in < < query;
parser.expression ();
}


where in , lexer and parser are instance variables of X, created in the constructor.


It works fine the first time evaluate() is invoked - but then seems to hack out because the lexer reached EOF the first time around i.e. need to somehow reset the parser with constructing it all over again

   <<Less

Re: Streaming Parser

Posted By:   alex_karasulu  
Posted On:   Wednesday, December 18, 2002 03:52 PM

Try using a pair of piped streams feeding the parser. Got to make sure that you don't rely on EOF to make top level production work otherwise the start method will not return.

here's an example:


m_parserIn = new PipedOutputStream() ;
PipedInputStream l_in = new PipedInputStream() ;
m_parserIn.connect(l_in) ;
antlrFilterLexer l_lexer = new antlrFilterLexer(l_in) ;
m_parser = new antlrFilterParser(l_lexer) ;
About | Sitemap | Contact