[antlr-interest] SOLVED Creation of Lexer and Parser in the loop? Bad idea

Ruslan Zasukhin sunshine at public.kherson.ua
Sat Oct 23 12:48:42 PDT 2004


On 10/19/04 4:20 PM, "Akhilesh Mritunjai" <virtualaspirin at yahoo.com> wrote:

> 
> Ruslan
> 
> Can you please share with us how you solved the issue
> ?

Here it is.

I have create class SqlParser which manage Lexer and Parser and TreeParser

// -------------------------------------------------------------------
class SqlParser
{
    protected:
    // instance data:

        antlr::ASTFactory    mAstFactory;
        
   //   STD::istringstream   mStrStream;
        vsql::CharBuffer     mCharBuffer;
        VSQL_Lexer           mLexer;
        VSQL_Parser          mParser;
        VSQL_TreeParser      mTreeParser;
};


// -------------------------------------------------------------------
SqlParser::SqlParser( void )
:
    mAstFactory(),
//  mStrStream( "" ),
    mCharBuffer( NULL, 0 ),
    mLexer( mCharBuffer ),
    mParser( mLexer ),
    mTreeParser()
{
    mParser.initializeASTFactory(mAstFactory);
    mParser.setASTFactory(&mAstFactory);
}

// -------------------------------------------------------------------
void SqlParser::ParseCommand( const String& inCommand, Environment& inEnv )
{
    ANTLR_USING_NAMESPACE(antlr)
    
    try
    {
        /** We need to convert query to the multi byte string
            (at least for now)... */
        StFromUTF16 QueryA(inCommand.c_str(),inCommand.length(),L"UTF8" );
        
        // init stream, lexer, parser:
        mCharBuffer.str( QueryA.c_str(), QueryA.length() );
        mLexer.getInputState()->reset();
        mParser.getInputState()->reset();

        
        // -------------------------
        // Parse the input expression
        mParser.sql();
        inEnv.mpTree = mTreeParser.sql( mParser.getAST() );
    }
    catch( std::exception& e )
    {
    }
}


AS YOU SEE the main job do 3 strings:

        // init stream, lexer, parser:
        mCharBuffer.str( QueryA.c_str(), QueryA.length() );

        mLexer.getInputState()->reset();
        mParser.getInputState()->reset();


Although note, that I use own CharBuffer to avoid STD streams,
And double copying related with them and code blow related with them.

All works as far as see.


-- 
Best regards,
Ruslan Zasukhin      [ I feel the need...the need for speed ]
-------------------------------------------------------------
e-mail: ruslan at paradigmasoft.com
web: http://www.paradigmasoft.com

To subscribe to the Valentina mail list go to:
http://lists.macserve.net/mailman/listinfo/valentina
-------------------------------------------------------------



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list